gpt4 book ai didi

javascript - 检查表中的所有数据值

转载 作者:行者123 更新时间:2023-11-28 06:48:27 26 4
gpt4 key购买 nike

我的代码如下:

<div class="input-group select-all" >
<span class="input-group-addon disabled">
<input type="checkbox" <?php if($pagetitle=="Trash") echo "disabled"?>>
</span>
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle <?php if($pagetitle=="Trash") echo "disabled"?>" data-toggle="dropdown" tabindex="-1">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Delete</a></li>
</ul>
</div>
</div><!-- /input-group -->

当我们选中复选框时,必须选择表中的所有数据,这就是我需要的操作类型。

<div class="mails">
<table class="table table-hover table-condensed">
<?php
if(count($inMessages)>0)
foreach($inMessages as $m):
?>
<tr data-id="<?php echo $m->sn?>" <?php if($m->flag==1) echo "class=\"read\""?><?php if($m->flag==0) echo "class=\"unread\""?>>
<td><?php if($pagetitle!="Trash"):?><i class="fa fa-check-square-o fa-square-o disabled" data-id="<?php echo $m->sn?>"></i><?php endif?></td>
<td class="subject"><?php echo $m->subject?></td>
<td class="body"><?php echo $m->message?></td>
<td>
<?php echo $m->address?>
<BR/><?php echo $m->io?>
</td>
<td class="time"><?php echo $m->mdate?> <?php echo $m->mtime?></td>
</tr>
<?php
endforeach
?>
</table>
</div>
</div><!-- /Right Side mail bar -->

手动复选框工作正常,但我需要检查所有选项。

除了上面的代码之外,我还能怎么做呢?请帮助我。

最佳答案

如果您想使用单个复选框选择所有内容,您可以使用类似于以下内容的内容:

<?php
$string .= '
<table id="mytable" class="table table-hover table-bordered datatable">
<thead>
<tr>
<th><input type="checkbox" id="selectall"></th>
<th>Field A</th>
<th>Field B</th>
</tr>
</thead>
<tbody>'."\n";
foreach($array as $row) { // create table content
$string .= ' <tr id="art-'.$row['field'].'" class="data">
<td><input class="case" type="checkbox" name="id[]" value="'.$row['field'].'"></td>
<td>'.$row['field A'].'</td>
<td>'.$row['field B'].'</td>
</tr>'."\n";
}
$string .= ' </tbody>
</table>
'."\n";
echo $string;
?>
<script>
$(document).ready(function(){
$("#selectall").click(function () { // check all
$('.case').prop('checked', this.checked);
});

// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").prop("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</script>

关于javascript - 检查表中的所有数据值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com