2016-06-15 89 views
-3

我有一個使用javascript和if循環的密碼檢查。但是,當我輸入不是javascript的字符串時,不顯示警報。這是我的代碼。Javascript密碼檢查器

<script type = "text/javascript"> 
function password_prompt() { 

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript 
    if (password == "javascript") { 
    var x = window.confirm("Please confirm you want to enter the webpage!"); 
     if (x != 1) { 
     window.close(); 
     window.open("https://www.google.com/"); 
    } 
    if (password != "javascript") { 
     window.alert("You entered the wrong password! Page will now close!"); 
    window.close(); 
    window.open("about:blank"); 
     } 

    } 
} 
</script> 
+8

縮進你的代碼,你會看到 – BeyelerStudios

+2

OT:JavaScript的認證是一個壞主意... :) –

+2

硬編碼密碼是一個壞主意 –

回答

-1

<script type = "text/javascript"> 
 
function password_prompt() { 
 

 
    var password = prompt("Please enter the correct password ", ""); //password = javascript 
 
    if (password == "javascript") { 
 
    var x = confirm("Please confirm you want to enter the webpage!"); 
 
     if (x != 1) { 
 
     window.close(); 
 
     window.open("https://www.google.com/"); 
 
    } 
 
    if (password != "javascript") { 
 
     alert("You entered the wrong password! Page will now close!"); 
 
    window.close(); 
 
    window.open("about:blank"); 
 
     } 
 

 
    } 
 
} 
 
</script>

+0

你也可以看http://www.w3schools.com/jsref/met_win_prompt.asp文檔 –

+0

當我輸入不同於javascript的東西,不顯示警報 –

+0

設置console.log(密碼)爲將看到密碼當前值 –

-1
<script type = "text/javascript"> 
function password_prompt() { 

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript 
    if (password == "javascript") { 
     var x = window.confirm("Please confirm you want to enter the webpage!"); 
     if (x != 1) { 
      window.close(); 
      window.open("https://www.google.com/"); 
     } 
    } 
    if (password != "javascript") { 
     window.alert("You entered the wrong password! Page will now close!"); 
     window.close(); 
     window.open("about:blank"); 
    } 
} 
</script>