我正在試圖製作一個網站,它與你的名字進行交互。 當你登錄時,你必須先輸入你的名字,爲此我使用一個提示窗口(Javascript),這裏的問題是用戶只需按下''取消''就可以輕鬆到達下一行代碼。 所以我做了這個:兩個「同時」條件?
while (userName === "" & userName === null); {userName = prompt("What's your name?")}
但是在用戶按下'取消'了兩次,只使用Javascript完全停止。 這是我的整個代碼,包括網站的HTML。忽略HTML :)
<!DOCTYPE html>
<html lang="en-US">
<title>
Javascript
</title>
<head>
</head>
<body>
<table>
<tr>
<td>
<script>
//Here I'll make a few variables for Javascript to work with.
var accessGranted = false
var userName
var userNameConfirmed = false
var userAge
var userAgeConfirmed = false
userName = prompt("What's your name?")
//Now I'll make a while that has two conditions to run.
while (userName === "" & userName === null); {
userName = prompt("Hvad hedder du?")
}</script>
</td>
</tr>
</table>
</body>
</html>
請參閱['while'(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while)和[邏輯運算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators) – georg