我正在生成大表,每行都有一个复选框,类“chcktbl”。
在表标题中,有一个全选复选框,类别为“chckHead”。
选择/取消选择所有功能工作正常,我在表标题中显示的选定图表的计数也是如此。
启用 Shift+单击功能以选择一系列复选框的功能也可以使用,但在当前格式下,在弹出窗口中生成错误消息之前仅选择 10 个复选框:
“停止运行此脚本?此页面上的脚本导致您的网络浏览器运行缓慢。如果它继续运行,您的计算机可能会变得无响应。”
<script type=text/javascript>
//select all button
$('#chckHead').click(function() {
if (this.checked === false) {
$('.chcktbl:checked').attr('checked', false);
}
else {
$('.chcktbl:not(:checked)').attr('checked', true);
}
countSelected();
});
//count number of boxes checked
function countSelected() {
var numCharts = $('input.chcktbl:checked').length;
$('#numCharts').html(numCharts);
}
//SHIFT+Click to select a range of checkboxes:
// this variable stores the most recently clicked checkbox
// it is used for shift-clicks
var lastClickedBox = 0;
// the checkbox functionality is default to the browser
$('.chcktbl').click(function(event) …Run Code Online (Sandbox Code Playgroud)