我有一个复选框,它将切换 html 表单上的一些其他复选框:
<input type="checkbox" name="selector" onclick="toggle_all(this);"/>
<script language="javascript">
function toggle_all(source) {
var checkboxes = $(":input[name^='form[r']");
if($(source).is(':checked')) {
checkboxes.attr('checked', 'checked');
} else {
checkboxes.removeAttr('checked');
}
alert('done');
}
</script>
第一次单击“选择器”复选框时,所有名称以“form[r”开头的复选框都会被选中。然后,当“选择器”复选框未选中时,所有其他复选框也未选中。从那时起选中/取消选中“选择器”复选框不会影响其他复选框。代码正在运行,因为 alert('done') 出现了。这里有什么问题?