在我的 html 中,我有以下函数调用
<input value="Roll" onclick="roll()" type="button">
它应该调用roll()
之前定义如下的函数:
<head>
<script language="javascript">
// roll function
// roll button pressed to roll the die and update as needed
function roll(){
wintotal = document.JForm.totalpoints.value;
var validate = Validate();
var p1total = document.JForm.p1turn.value;
var p2total = document.JForm.p2turn.value;
var dienumber = Math.floor(Math.random() * (6 - 1 +1)) + 1;
if (validate){
// put together image for die graphic that was rolled
document.getElementById("dice").innerHTML = '<img src="die_face_'+dienumber+'.png"/>';
}
else if (validate == 0){
document.getElementById("message").innerHTML ="ERROR: Play to points not in range";
}
else{
document.getElementById("message").innerHTML ="ERROR: Play to points not in valid integer";
}
} // end roll function
</script>
</head><body>
但是,当我单击 HTML 页面按钮时,我收到一条错误消息,roll
即未定义,即使它已在其上方明确定义,有人有什么想法吗?