2016-06-15 2 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

set console.log (password) for будет видеть текущее значение пароля –

-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> 
Смежные вопросы