私はJQuery ValidationをWebForms/htmlで使用しています。jQueryの妥当性検査 - クリック時の妥当性チェックを使用して、サブミット時ではありません
私は基本的に(実際のHTMLを簡素化する要素のみを示す)、持っている:検証/アクションの
<input id="txtEmail"/>
<input id="txtTicketID"/>
<a id="create" href="#">Create a new ticket</a>
<a id="find" href="#">Find this ticket</a>
のjavascriptはここにある:それは全く機能していない
$(function() {
$("#aspnetForm").validate({
rules: {
txtEmail: {
required: true,
email: true
,
messages: {
required: "* enter your e-mail",
email: "* invalid e-mail"
}
},
txtTicketID: {
required: true,
digits: true,
messages: {
required: "*",
digits: "* invalid ticket"
}
}
},
onfocusout: true,
onkeyup: true,
onsubmit: false,
debug: true
});
$("#create").click(function() {
if ($("#aspnetForm").valid()) {
var email = $("#txtEmail").val();
if (email != "")
window.location = "CreateTicket.aspx?email=" + email;
}
});
$("#find").click(function() {
if ($("#aspnetForm").valid()) {
var email = $("#txtEmail").val();
var ticketID = $("#txtTicketID").val();
if (email != "" && ticketID != "")
window.location = "DetailEditTicket.aspx?email=" + email + "&ticketID=" + ticketID;
}
});
});
。フィールドが空白であるか間違っていても、リンクclickのvalid()は常にtrueを返します。
何かを入力したり、ぼかしなどをすると、何も検証が行われません。
あなたはこれに欠けているものを見ますか?
Steerpikeは正解です。さらに、上記のルールとしてclass = "required email"などを入力する代わりに、inputにタグを付けることで少し簡略化できます。フォームでバリデーションを呼び出すと、プラグインがこれを取得します。 – lucas