dongta5621 2017-01-27 07:32
浏览 1142

在表格上添加复选框按钮

Hi i'm making a project using php i just wonder how i can add checkbox on a table that indicate being selected. As I didn't find any question asked before, on how to toggle checkbox on click of a table row, so I'd like to share my approach to this.

here are my codes:

$list_equipments = array();

$con = new data_abstraction("resource_booking", "it_equipment_type");
if ($result = $con - > make_query() - > result) {
    while ($data = $result - > fetch_assoc()) {
        $list_equipments[] = $data;
    }
} else {
    die("SQL Error:".$con - > error);
}


$html - > draw_container_div_start();
$html - > draw_fieldset_header('');
$html - > draw_fieldset_body_start();


echo "<table width='600px' style='border-width:1px; border-style:solid;'>";

$counter = 0;
$no_columns = 2; //initialize 3 columns
$column_width = 110 / $no_columns; +
foreach($list_equipments as $key => $equipment) {

    if ($counter % $no_columns == 0)
        echo "<tr>";
    echo "<td width='".$column_width.
    "%' style='border-width:1px; border-style:solid'>";
    draw_equipment($equipment);
    echo "</td>";
    if ($counter % $no_columns == $no_columns - 1)
        echo "</tr>";
    $counter++;
}
echo "</table>";

$html - > draw_fieldset_body_end();
$html - > draw_fieldset_footer_start();

$html - > draw_submit_cancel(true, '2', 'btn_submit', 'RESERVE');
$html - > draw_fieldset_footer_end();
$html - > draw_container_div_end();
$html - > draw_footer();


function draw_equipment($equipment) {
    $equipment_name = $equipment['img_link'];
    echo "<div style='text-align:left;width:120%'>";
    echo "<img src='img/$equipment_name' alt='$equipment_name' width='155px'/><br/>";
    echo $equipment['equip_type'];
}

echo "</form>";
return ob_get_clean();
  • 写回答

2条回答 默认 最新

  • duanlei1957 2017-01-27 07:57
    关注

    While creating table you can add a td in which you can add a checkbox for each row like below

    <td><input type= "checkbox" class="toggleCheckbox"></td>
    

    And then using jquery you can handle click event on this like below

    $("table tr").click(function(){
        ($(this).children(":last").trigger("click");
    })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路