我有一个表单,我检查密码是否相同,但我得到Unexpected end of input
错误。谁能告诉我我的错误在哪里?
JS代码:
<script>
$( document ).ready(function() {
$( "form" ).submit(function(event) {
var $form = $( this );
if( $form.find( '#password').val() !== $form.find( '#password2' ).val()) {
event.preventDefault();
alert( 'Passwords do not match.' );
}
});
</script>
并形成HTML代码:
<form name="form1" method="post" action="process_reset.php">
<img src="../images/login_icon.png" class="form-icon"/><div id="clr"></div><span style="float: left;padding-left: 10px;">
<b>Welcome admin.</b> <i>Reset your password</i></span><br/>
<input name="password" type="text" class="login-text-lbl" placeholder="password" id="password"><div id="clr"></div>
<input name="password2" type="password2" class="login-text-lbl" placeholder="repeat password" id="password2"><div id="clr"></div>
<input name="admin_id" type="text" value="<? echo $client_id; ?>" style="display: none;" id="admin_id"/>
<input type="submit" id="resetBtn" name="Submit" value="Reset password" class="login-button">
</form>
答案 0 :(得分:3)
Yup missing}); 您还应该考虑使用type =“password”作为输入字段。像这样:
<input name="password" type="password" class="login-text-lbl" placeholder="password" id="password">
<div id="clr"></div>
<input name="password2" type="password" class="login-text-lbl" placeholder="repeat password" id="password2"><div id="clr"></div>
答案 1 :(得分:2)
您尚未关闭$( document ).ready(
来电。缺少结束});
。
$( document ).ready(function() {
$( "form" ).submit(function(event) {
var $form = $( this );
if( $form.find( '#password').val() !== $form.find( '#password2' ).val()) {
event.preventDefault();
alert( 'Passwords do not match.' );
}
});
}); // <-- this was missing