如何创建密码以显示html和js中的隐藏消息

问题描述

我是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>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...