3

如果选中任何行复选框,我想在表格下方显示删除按钮。否则,该按钮应保持隐藏状态。

表我希望它被实施。表格截图: 在此处输入图像描述

这是后面的html表格代码。

      <table id="datatable_example" class="responsive table table-striped table-bordered" style="width:100%;margin-bottom:0; ">
        <thead>
          <tr>
            <th style="width:0px; padding-right:0px;" class="jv no_sort"> <label class="checkbox ">
                <input type="checkbox">
              </label>
            </th>
            <th style="width:200px;" class=""> Skill </th>
            <th style="width:300px;" class="to_hide_phone  no_sort"> Description </th>
            <th class=""> Rating </th>
            <th style="width:200px;" class="ue no_sort"> Date </th>
            <th class="ms no_sort "> Actions </th>
          </tr>
        </thead>
        <tbody>
        <?php echo $skills; ?>
        </tbody>
      </table>

这是技能变量:

$skills="";
while($row=mysql_fetch_array($skills_list))
{
    $showskillid=$row['skill_id'];
    $showskillname=$row['skill_name'];
    $showskilldescription=$row['skill_desc'];
    $showskillrating=$row['skill_rating'];
    $showskill_lastupdated=$row['last_updated'];
    $skills .="<tr>
                    <td><label class=\"checkbox\">
                        <input type=\"checkbox\" class=\"chkboxes\" name=\"ids[]\">
                      </label></td>
                    <td class=\"to_hide_phone\"> $showskillname </td>
                    <td class=\"to_hide_phone\">$showskilldescription</td>
                        <td> $showskillrating </td>
                    <td> $showskill_lastupdated </td>
                    <td class=\"ms\"><div class=\"btn-group1\"> <a href=\"skill_edit.php?id=$showskillid\" class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"left\" data-original-title=\" edit \"><i class=\"gicon-edit\"></i></a> <a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"top\" data-original-title=\"View\"><i class=\"gicon-eye-open\"></i></a> <a class=\"btn  btn-small\" rel=\"tooltip\" data-placement=\"bottom\" data-original-title=\"Remove\"><i class=\"gicon-remove \"></i></a> </div></td>
                  </tr>";
}

我尝试过的 Jquery 但我知道我是 jquery 的新手,所以需要帮助来修复它。

    <script type="text/javascript">
$(document).ready(function() {
    $('.delbtn').hide();
 });


$('.chkboxes').click(function(){
    $('.delbtn').toggle();
});

</script>

Jquery 我尝试过它的工作方式就像我单击一个复选框时按钮显示,当我去单击另一个复选框时按钮消失?

我知道不应该在这里使用切换。我应该在这里使用什么来解决这个问题,或者如果有更好的选择来解决它,我愿意接受它。

4

1 回答 1

3

当至少一个复选框被选中时,这将显示删除按钮。

$('.chkboxes').change(function(){
    $('.delbtn').toggle($('.chkboxes:checked').length > 0);
});

但不是隐藏它,更常见的方法是启用和禁用按钮:

$('.delbtn').prop('disabled', true);

$('.chkboxes').change(function(){
    $('.delbtn').prop('disabled', $('.chkboxes:checked').length == 0);
});
于 2013-01-26T06:50:25.947 回答