为什么在下面的代码中调用document.write
函数时validator()
表单元素(复选框和按钮)从屏幕上删除?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function validator() {
if (document.myForm.thebox.checked)
document.write("checkBox is checked");
else
document.write("checkBox is NOT checked");
}
</script>
</head>
<body>
<form name="myForm">
<input type="checkbox" name ="thebox"/>
<input type="button" onClick="validator()" name="validation" value="Press me for validation"/>
</form>
</body>
</html>