我需要提示访问者输入 1 到 100 之间的整数,然后继续提示,直到输入有效数字。
这是我的:
<script>
var number = parseInt(prompt("Please enter a number from 1 to 100", ""));
if (number < 100) {
document.write("Your number (" + number + ") is matches requirements", "");
} else if (isNaN(number)) {
parseInt(prompt("It is not a number. Please enter a number from 1 to 100", ""));
} else {
parseInt(prompt("Your number (" + number + ") is above 100. Please enter a number from 1 to 100", ""));
}
</script>
它识别号码但当号码错误时无法重新询问。你能帮我解释一下你添加了什么吗?
非常感谢。
最佳答案
像这样的东西应该可以解决问题:
do{
var selection = parseInt(window.prompt("Please enter a number from 1 to 100", ""), 10);
}while(isNaN(selection) || selection > 100 || selection < 1);
关于javascript提示编号,如果答案错误则继续提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15047140/