【发布时间】:2017-05-22 12:33:33
【问题描述】:
点击对象时,出现提示,但提交答案时没有任何反应。密码命名有问题吗?非常感谢任何建议!
var password;
var pass1 = "thailand";
password = function password() {
prompt('What was the first country we visited together?');
};
if (password == pass1) {
//Change the page here
console.log("Correct");
} else {
console.log('sorry, try again!')
};
<div class='one'>
<p onclick="password()">Click me!</p>
【问题讨论】:
-
在 JS 文件中检查密码是个坏主意。
-
那是因为你的if语句是在你的密码函数被调用之前执行的,而不是再次被调用
-
你需要在
functon password() { }中做所有的事情 -
“你不能这样设置内联函数”为什么不呢?
-
@evolutionxbox 我已经纠正了,你可以的 :)
标签: javascript if-statement prompt