0

我有一个表格,我检查密码是否相同,但我收到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>
4

2 回答 2

3

是的,缺少 }); 此外,您应该考虑在输入字段中使用 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>
于 2013-10-11T09:58:12.153 回答
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
于 2013-10-11T09:53:47.563 回答