我有一个名为myVar
. 当您单击复选框时,它的值会发生变化。单击复选框时,您将看到一个显示其值为 1 的警报框。当您取消选择它时,它将再次显示一个值为 0 的警报框。这是正确的。
现在我有2个问题。
当我尝试通过单击提交文档时,
Submit
我收到错误消息Uncaught ReferenceError: confirm_submit is not defined
。为什么?当我将
confirm_submit
函数从. 为什么?函数内不可访问吗?ready event
undefined
myVar
myVar
confirm_submit
代码:
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.treeTable.js"></script>
<script type="text/javascript">
var myVar;
jQuery(document).ready(function() {
$("#myTable2").treeTable({
expandable: true,
clickableNodeNames: true,
initialState: "expanded",
});
document.getElementById('myVar').addEventListener('click', myVar, false);
function myVar() {
if (document.getElementById('myVar').checked === true) {
myVar = 1;
} else {
myVar = 0;
}
alert(myVar);
}.................
some functions....................
function confirm_submit() {
alert(myVar);
if (confirm('Press OK to confirm')) {
document.myform.myVar.value = myVar;
document.myform.submit();
reload_parent_and_close_window();
}
}
and some more functions.....................
});
</script>
</head>
<body>
<form name="myform" id="myform" action="$action" method="post" onsubmit="return false;">
<input type="checkbox" name="myVar" id="myVar" value="myVar">Text here
</form>
<a href="javascript:confirm_submit()">Submit</a>
</body>
</html>