在我的HTML我有以下函数调用JavaScript函数调用说不确定,但功能被定义
<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
是未定义的,即使它在上面明确定义,任何人有任何想法?
你确定这是'roll'的问题,而不是像'Validate'或其他其他功能? – DontVoteMeDown
你能张贴你确切的错误信息得到了吗? – bfavaretto