似乎每次单击复选框都会触发页面正文中的 checkDisplay 。但是怎么做?该功能似乎没有与复选框绑定......
<!DOCTYPE html>
<html>
<head>
<title>Checkbox</title>
<script type="text/javascript">
var checkDisplay = function(check, form) { //check ID, form ID
form = document.getElementById(form), check = document.getElementById(check);
check.onclick = function(){
form.style.display = (this.checked) ? "block" : "none";
form.reset();
};
check.onclick();
};
</script>
</head>
<body>
<input type="checkbox" id="check" />
<form id="form">
<input type="checkbox" /><input type="text" />
</form>
<script type="text/javascript">
checkDisplay("check", "form");
</script>