我是 HTML 和 js 的新手,目前我正在尝试让用户输入密码,如果密码正确,它会显示一条隐藏的消息。这是我到目前为止得到的。我无法让它工作。
这是 HTML:
<form id="form" onsubmit="return false;">
<input type="text" id="userInput" />
<input type="submit" onclick="othername();" />
</form>
<p id="hidden_clue"></p>
这是js:
var pass1 = 3736.62417618;
var input = document.getElementById("userInput").value;
alert(input);
if (input == pass1) {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
最佳答案
您很接近,但是在 getElementById
上,您需要选择要获取的元素的 ID。
function othername() {
var pass1 = 3736.62417618;
var input = document.getElementById("userInput").value;
if (input == pass1) {
document.getElementById("hidden_clue").textContent = "Hello JavaScript!";
}
}
<form id="form" onsubmit="return false;">
<input type="password" id="userInput" />
<input type="submit" onclick="othername();" />
</form>
<p id="hidden_clue"></p>
关于javascript - 如何创建一个密码,以显示 html 和 js 中的隐藏消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63476258/