gpt4 book ai didi

javascript - JavaScript 未执行

转载 作者:行者123 更新时间:2023-11-28 16:05:39 26 4
gpt4 key购买 nike

在获取请求发送密码匹配之前,我有以下 html 表单,使用 js 完成密码匹配,但 js 不起作用

<html>
<title>Login System</title>
<head>
<script type="text/javascript">
function match()
{
var s1=document.getElementById('t4').value;
var s2=document.getElementById('t5').value;
if (s1 == s2)
{
alert('yep');
}
else
{
alert('Passwords Does not Match');
}
}
</script>
</head>
<style type="text/css">
div.ex {
width:220px;
padding:10px;
border:5px solid gray;
margin:10px;
}
</style>

<body>
<div class="ex">
<strong>User Login</strong>
<form name=f1 method=get action="http://localhost:8080/login">
User &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=text name=t1><br>
Password <input type=password name=t2><br>
<input type=submit name=sub value="Login">
</form>
</div>
<div class="ex">
<strong>User Registration</strong>
<form name=f2 method=get action="http://localhost:8080/login">
User Name &nbsp&nbsp&nbsp&nbsp&nbsp<input type=text name=t3><br>
Password <input type=password name=t4><br>
Password <input type=password name=t5><br>
<input type=submit name=sub value="reg" onclick='match();'>
</form>
</div>

</body>
</html>

最佳答案

getElementById 查找 id 属性,而不是上面使用的 name

更改:

Password <input type=password name=t4><br>

Password <input type=password name=t4 id='t4'><br>

关于javascript - JavaScript 未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15060446/

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