如果您運行此腳本,並在它從來沒有運行其他的提示框中輸入2,我不知道爲什麼。這是我如何設置不正確的var或myFunction。在我的測試腳本中,我得到了我的if語句運行,但我從來沒有得到其他的運行?我做錯了
<!DOCTYPE html>
<html>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
var x=1;
var name=prompt("Please enter a number one");
if (x===1)
{
alert("good");
}
else
{
alert("not a number 1");
}
}
</script>
</body>
</html>
他總是可以使用'parseInt'如果他希望用戶輸入一個數字。 – xbonez
反正編輯以包括兩者。 – xbonez