2016-01-25 20 views
0

嗯,我正在嘗試如何驗證密碼,如果它們匹配,我多次測試並嘗試更改它的位但它仍然不會說已驗證或未驗證。 ..我很抱歉,如果我沒有看到明顯的東西,我也嘗試在網上搜索一下,但我真的需要做到這一點。非常感謝幫助。檢查密碼是否匹配不起作用

<html> 
<head> 
<title>FA3</title> 
</head> 
<body> 
<style type="text/css"> 
.font 
{ 
font-family:Helvetica Neue; 
text-align:center 
} 
</style> 
<div class="font"> 
<h2>Verify Password</h2> 
Type Password : <input type="text" id="first"> 
<br> 
Retype Password : <input type="text" id="second"> 
<hr> 
<button onclick="verify()">Submit</button> 
<br> 
<p id="result">Your Password is</p> 
</div> 
<script> 
function verify(){ 
    var t = document.getElementbyId("first").value; 
    var r = document.getElementbyId("second").value; 
if (t==r){ 
document.getElementById("result").innerHTML ="Verified" 
} 
else{ 
document.getElementById("result").innerHTML ="Not Verified" 
}} 
</script> 
</body> 
</html> 
+1

(偏離主題,但有點相關)您可能希望使用更「適當的」類型的密碼,而不是隻使用「文本」字段。 – Scar

回答

3

這只是一個錯字 - 的verify()前兩行有document.getElementbyId而不是document.getElementById(大寫B)。

+0

犯了錯誤......我現在覺得很愚蠢。謝謝。 – Marck

0

這裏是工作代碼:

<html> 
<head> 
<title>FA3</title> 
</head> 
<body> 
<style type="text/css"> 
.font 
{ 
font-family:Helvetica Neue; 
text-align:center 
} 
</style> 
<div class="font"> 
<h2>Verify Password</h2> 
Type Password : <input name="first" type="text" id="first"> 
<br> 
Retype Password : <input name="second" type="text" id="second"> 
<hr> 
<button onclick="verify()">Submit</button> 
<br> 
<p id="result">Your Password is</p> 
</div> 
<script> 
function verify(){ 
    var t = document.getElementById("first").value; 
    var r = document.getElementById("second").value; 
if (t==r){ 
document.getElementById("result").innerHTML ="Verified" 
} 
else{ 
document.getElementById("result").innerHTML ="Not Verified" 
}} 
</script> 
</body> 
</html> 

https://jsbin.com/cataweboda/edit?html,output

唯一的問題是,的getElementById編寫不正確。它是區分大小寫的。

相關問題