为什么我的函数提示(Javascript)不起作用?

时间:2017-02-11 10:56:46

标签: javascript html html5 prompt adobe-brackets

我不明白为什么我的功能仅适用于"现场演示" ' Brackets',但当我尝试使用我的index.html文件打开它时...

这是我的密码保护区功能:

.macro b;a(%rip);.endm

请帮助我,谢谢大家:D

2 个答案:

答案 0 :(得分:0)

这是一个很好的功能..无论如何,你实际上是在调用index.html中的函数吗?

<html>
<head>
   <script>
      function passWord() {
         //... (place your code here)
      }
   </script>
</head>
<body onload="passWord()"></body> <!--here you actually call the function-->
</html>

这只是一个选项,在html中使用事件调用者有点不满意。您还可以在脚本标记中添加函数调用:

<script>
   function passWord() {
       //... (place your code here)
   }
   passWord(); //now the function actually gets executed
</script>

答案 1 :(得分:0)

因为您正在使用history.go(0);刷新页面,该页面会重置testV的值。

我添加了一些控制台日志,以便您可以看到正在发生的事情:

function passWord() {
  var testV = 1;
  var pass1 = prompt('Please Enter Your Password');
  while (testV < 3) {
    if (pass1.toLowerCase() == "letmein") {
      alert('You Got it Right!');
      window.open('/html/ok.html', "_self");
      break;
    }
    testV++;
    var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again.');
    console.log(testV);
  }
  if (pass1.toLowerCase() != "password" & testV == 3)
  {
    console.log("Refresh");
    history.go(0);
  }
  return " ";
}

passWord();

小提琴:https://jsfiddle.net/s2ejwk9p/

取出history.go(0);,你会没事的。

相关问题