Javascript 在表上添加复选框按钮

Javascript 在表上添加复选框按钮,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,嗨,我正在用php做一个项目,我只是想知道如何在一个表上添加复选框来表示被选中。因为我以前并没有发现任何关于如何在点击表格行时切换复选框的问题,所以我想分享一下我的方法 这是我的密码: $list_equipments = array(); $con = new data_abstraction("resource_booking", "it_equipment_type"); if ($result = $con - > make_query() - > result) {

嗨,我正在用php做一个项目,我只是想知道如何在一个表上添加复选框来表示被选中。因为我以前并没有发现任何关于如何在点击表格行时切换复选框的问题,所以我想分享一下我的方法

这是我的密码:

$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();
$list_devices=array();
$con=新的数据抽象(“资源预订”、“it设备类型”);
如果($result=$con->make_query()->result){
而($data=$result->fetch_assoc()){
$list_设备[]=$data;
}
}否则{
die(“SQL错误:.$con->错误);
}
$html->draw_container_div_start();
$html->draw_fieldset_头(“”);
$html->draw_fieldset_body_start();
回声“;
$counter=0;
$no_列=2//初始化3列
$column\u width=110/$no\u列+
foreach($key=>$device列出设备){
如果($counter%$no_列==0)
回声“;
回声“;
牵引设备($设备);
回声“;
如果($counter%$no_columns==$no_columns-1)
回声“;
$counter++;
}
回声“;
$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();
功能图设备($设备){
$equipment_name=$equipment['img_link'];
回声“;
回声“
”; echo$设备['equipment_type']; } 回声“; 返回ob_get_clean();
在创建表格时,您可以添加一个td,您可以在其中为每行添加一个复选框,如下所示

<td><input type= "checkbox" class="toggleCheckbox"></td>
$("table tr").click(function(){
    ($(this).children(":last").trigger("click");
})

在创建表时,您可以添加一个td,您可以在其中为每一行添加一个复选框,如下所示

<td><input type= "checkbox" class="toggleCheckbox"></td>
$("table tr").click(function(){
    ($(this).children(":last").trigger("click");
})

我终于有了解决我问题的办法

<?php

$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 "<input type='checkbox' class='toggleCheckbox'>";
    echo "<img src='img/$equipment_name' alt='$equipment_name' width='120px'/><br/>";
    echo $equipment['equip_type'];
}

echo "</form>";
return ob_get_clean();

最后我对我的问题有了一个解决方案

<?php

$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 "<input type='checkbox' class='toggleCheckbox'>";
    echo "<img src='img/$equipment_name' alt='$equipment_name' width='120px'/><br/>";
    echo $equipment['equip_type'];
}

echo "</form>";
return ob_get_clean();

我只是在编码的最后一部分添加了另一个echo:echo“”;我只是在编码的最后一部分添加了另一个echo:echo“”;