【发布时间】:2014-02-03 05:17:07
【问题描述】:
我想在 HTML5 中验证密码并确认密码。通过使用所需的功能,我已经验证了空值。但无法验证密码和确认密码
HTML:
<form id="registration" name="registration" action="registrationaction.php" method="POST">
<input type="password" class="agent-input registerinput" name="pswd" id="pswd">
<input type="password" class="agent-input registerinput " name="confirmpassword" id="confirmpassword">
</form>
JavaScript:
<script>
$().ready(function()
{
$("#registration").validate({
rules: pswd: {
required: true
},
confirmpassword: {
required: true
},
},
messages
pswd: "Please enter password",
confirmpassword: "Please enter valid confirm password",
},
submitHandler: function() { $('#registration').submit(); }
});
});
【问题讨论】:
-
在 jquery 中编写逻辑...
-
使用
$(document).ready(function() { // code here })你没有写document关键字。 -
是的,您可以通过 jquery 获取某个变量中的值来检查两者是否相等。
-
还请注意,这种验证实际上没有任何意义,除了作为用户的便利因素之外,因为它是客户端。还包括来自服务器端的这项检查。
-
你看到@user2727841的代码了吗...
标签: javascript jquery html