jquery検証プラグインをonkeyupまたはonfocusoutオプションとともに使用しようとしています。これらのオプションを追加してそのうちの1つを起動するたびにエラーが発生します。私のフォームを提出すると、検証が機能します。f.settings [g] .callは、検証を送信する以外の機能を持つ関数ではありません。
私は作業しているフォームを投稿することは実際に許可されていませんが、非常にシンプルなフォームで同様の問題を作成しましたが、サブディレクトリstatic/js /の下にあるすべてのjでディレクトリにロードしています。
私は誰もがどんな考えを持っているjQueryの1.6.2とjQueryの検証1.9.0
を使用していますか?
<html>
<script type="text/javascript" src="static/js/jquery.js"></script>
<script type="text/javascript" src="static/js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var validator = $('#submitform').validate({
rules: {
name: 'required',
phone: {
required: true,
minlength: 12
},
team: {
required: true,
minlength: 1
},
fax: {
required: true,
minlength: 12
}
},
messages: {
name: 'Your name is required',
phone: 'Your phone number is required',
team: 'Your extension number is required',
fax: 'Your fax number is required'
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
if (element.is(":radio"))
error.appendTo(element.parent().next().next());
else if (element.is(":checkbox"))
error.appendTo (element.next());
else
error.appendTo(element.parent());
},
onfocusout: true,
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function() {
alert("submitted!");
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
}
});
});
</script>
<form id="submitform" action=".">
<label for="name">Your Name:</label>
<input id="ins_name" type="text" name="name" maxlength="40" />
<label for="phone">Phone:</label>
<input name="phone" maxlength="14" type="text" id="phone" />
<label for="extension">Extension:</label>
<input name="extension" maxlength="10" type="text" id="extension" />
<label for="fax">Fax:</label>
<input name="fax" maxlength="14" type="text" id="fax" />
<input type="submit" value="Submit">
</form>
私はonfocusoutが関数であるべきだと推測します。 – AutoSponge
ドキュメントによると、それは単なるオプションです - http://docs.jquery.com/Plugins/Validation/validate#toptions – grantk
オプションは設定オブジェクトのプロパティで、その値は何でもかまいません。この場合、イベントハンドラ(jQueryでよく見られる)のために型が関数でなければならないと推測しています。(ほとんどのプラグインのように)よく書かれていません。 – AutoSponge