有个问题。这是我的代码:
<html>
<body>
<form>
<p>13-7: <input id="in1" type="text"" /><input type="submit" onclick="check(6, 'in1', 'out1')" value="Tjek!"/></p>
<p id="out1"></p>
<p>20-7: <input id="in2" type="text"" /><input type="submit" onclick="check(13, 'in2', 'out2')" value="Tjek!" /></p>
<p id="out2"></p>
<script type="text/javascript">
function check(facit, input, output) {
var answer, evaluation;
answer = document.getElementById(input).value;
evaluation = (answer == facit) ? "Correct" : "Wrong";
document.getElementById(output).innerHTML = evaluation;
return false;
}
</script>
</form>
</body>
</html>当我点击提交按钮时,“正确/错误”只显示了一小段时间。我想让它留在网站上,有什么建议吗?
发布于 2012-07-02 04:35:09
提交按钮正在提交您的表单(因此重新加载您的页面)。
将按钮更改为type="button"。
发布于 2012-07-02 04:34:48
您的按钮是提交按钮(<input type="submit">),因此它们将提交表单并在每次单击时刷新页面。改为将按钮更改为<input type="button">。
发布于 2012-07-02 04:34:59
将onclick函数从:
onclick="check(13, 'in2', 'out2')"至:
onclick="return check(13, 'in2', 'out2')"或者,如果您不想提交表单,因为您有两个提交按钮,最好使用:
<input type="button" />https://stackoverflow.com/questions/11285412
复制相似问题