検証が必要なログイン フォームがあります。ボタンがいくつかあります。ユーザーがボタンの値を忘れた場合にエラーにフラグを立てるような方法でフォームを検証する必要があります。ただし、成功すると、新しいページに移動して作業を続行します。私は次のものを持っていますが、検証は行われていません。
JQ :
<script type="text/javascript">
$(function() {
$('#txtEmpid').click(
{
rules: {
txtEmpid: {
required: true
}
},
errorPlacement: function(error, element) {
element.css('background', '#ffdddd');
}
});
$('#txtPassword').click(
{
rules: {
txtPassword: {
required: true
}
},
errorPlacement: function(error, element) {
element.css('background', '#ffdddd');
}
});
});
</script>
HTML フォーム (index.html):
<FORM NAME="frmLogin" ACTION="Login.jsp" METHOD="post" >
<fieldset>
<div class="text-center">
<label class="text-center" for="txtEmpid">Employee Id </label>
<div class="text-center">
<input type="text" id="txtEmpid" name ="txtEmpid" placeholder="Employee Id">
</div>
</div>
<div class="text-center">
<label class="text-center" for="txtPassword">Password</label>
<div class="text-center">
<input type="password" id="txtPassword" name ="txtPassword" placeholder="Password">
</div>
</div>
<div class="text-center">
<div class="text-center">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</FIELDSET>
上記は機能しません。.validate jquery method を使用して送信フォーム全体の検証を行うことができるため、jquery プラグインは正しいと確信しています。
すべてのボタンを検証したい。値に問題がない場合は、新しいページ (Login.jsp) に移動します。それ以外の場合は、index.html にとどまり、問題にフラグを立てます。どうすればいいのですか ?私の間違いは何ですか?