<script type="text/javascript">
$(function () {
$("#chckAll").click(function () {
//$("input[name='chckList']").attr("checked", $("#chckAll").attr("checked")); 失败!
var flag = $(this).prop("checked");
alert(flag);
if (!flag) {
$("[name = 'chckList']:checkbox").attr("checked", false);
}
else {
$("[name = 'chckList']:checkbox").attr("checked", true);
}
});
});
</script>
本文介绍了一个使用jQuery实现的全选与取消全选功能。通过点击一个全选按钮,可以为页面上的所有指定复选框设置选中状态或取消选中状态。该功能适用于需要批量操作选项的场景。
183

被折叠的 条评论
为什么被折叠?



