【发布时间】:2017-05-25 17:30:16
【问题描述】:
如何在页面加载后单击复选框时选择所有复选框。
我的html代码是,
<table id="dealer_select_list" class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
<th>Customer Name</th>
<th><input id="selectall" type="checkbox">Select All</th>
</tr>
</thead>
<tbody id="Dlist_cont">
</tbody>
</table>
单击按钮后会显示剩余的复选框。代码是,
$list .= "<td><input id='checkBox' class='checkbox' type='checkbox' value='{$dl['id']}'></td>";
我的 jquery 代码是,
$('#selectall').click(function () {
if (this.checked) {
$(':checkbox').each(function () {
this.checked = true;
});
} else {
$(':checkbox').each(function () {
this.checked = false;
});
}
});
此代码不起作用,因为我认为复选框在页面加载后出现。我该如何解决这个问题?
【问题讨论】:
-
显示你的 HTML ?
-
我在上面添加了html代码
-
你把你的代码放在 $(document).ready(funtion(){}) 中?