如果文字框為空,則返回true
2001年12月31日終了的兩年期收入和支出及準備金和基金結餘變動報表
否則,顯示確認
工作測試: http://next.plnkr.co/edit/KfD3oznkl3eBXgPx
我想做的是:
當用戶輸入嘗試單擊“提交”並且密碼文字欄位為空白時,它應該直接返回true
,但如果密碼文字欄位有資料,它應該顯示確認提示.
我做了什麼:
當密碼文字欄位為空時,它直接返回true
,但是當有值時,它顯示確認,但即使我點選確認框中的“no”,它也返回true
碼:
<script>
function validateForm(e) {
var password=document.getElementById("password").value;
if (password==""){
return true;
}
else{
confirm("Are You Sure you wanted to change password?");
}
}
</script>
<h1> Edit Profile </h1>
<form onSubmit="return validateForm()">
<input type="text" placeholder="Username" id="uname"><br>
<input type="password" placeholder="password" id="password"><br>
<input type="text" placeholder="email" id="email"><br>
<input type="submit" id="check" value="OK">
</form>