gpt4 book ai didi

javascript - 使用 JavaScript 返回 HTML 输入

转载 作者:行者123 更新时间:2023-12-02 21:47:40 25 4
gpt4 key购买 nike

我想让我的代码使用警报返回 HTML 输入。

我尝试使用下面的代码,但输出什么也没有。我很确定这不是按钮...

<center>
<h3>Enter The Username And Password To Unlock This Computer</h3>
<script>
function incorrect() {
var user = document.getElementById("username");
var pass = document.getElementById("password");
text = "the username '" + user + "' is incorrect, and the password '" + pass + "' is also incorrect"
console.log(text)
alert(text)
}
</script>
<form>
<h6>Username</h6><input type="text" id="username" name="username" value="">
<h6>Password</h6><input type="text" id="password" name="password" value="">
<br><button type="button" onclick="incorrect">Unlock</button>


</form>
</center>

最佳答案

您想要正在输入的文本还是只是 html 输入 block ?

<center>
<h3>Enter The Username And Password To Unlock This Computer</h3>
<script>
function incorrect() {
var user = document.getElementById("username").value;
var pass = document.getElementById("password").value;
text = "the username '" + user + "' is incorrect, and the password '" + pass + "' is also incorrect"
console.log(text)
alert(text)
}
</script>
<form>
<h6>Username</h6><input type="text" id="username" name="username" value="">
<h6>Password</h6><input type="text" id="password" name="password" value="">
<br><button type="button" onclick="incorrect()">Unlock</button>


</form>
</center>

关于javascript - 使用 JavaScript 返回 HTML 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60216609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com