[更新しました]
単純なフォームを検証するためにJQueryValidateプラグインを使用しています。HTML形式です:
<form id="commentForm">
<div id="ContactUsDIV">
<div id="right">
<div class="ContactFormInput">Subject:</div>
<input id="ContactFormSubject" name="ContactFormSubject" type="text" class="input"/>
<label for="ContactFormSubject" class="validationMessage"></label>
<div class="ContactFormInput">Full Name:</div>
<input id="FullName" name="FullName" type="text" class="input"/>
<label for="FullName" class="validationMessage"></label>
<div class="ContactFormInput">EMail:</div>
<input id="EmailAddress" name="EmailAddress" type="text" class="inputLTR"/>
<label for="EmailAddress" class="validationMessage"></label>
<div>
<input id="SendMessage" type="submit" value="Send" class="ContactFormSubmit"/>
</div>
</div>
<div id="left">
<div class="ContactFormInput">Message:</div>
<textarea id="UserComment" cols="20" rows="2"></textarea>
<label for="UserComment" class="validationMessage"></label>
</div>
</div>
</form>
Javaスクリプト:
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function () { alert("submitted!"); }
});
$().ready(function () {
// validate signup form on keyup and submit
$("#commentForm").validate({
rules: {
ContactFormSubject: "required",
FullName: "required",
username: "required",
EmailAddress: {
required: true,
email: true
},
UserComment: "required"
},
messages: {
ContactFormSubject: "blah blah",
FullName: "blah blah",
username: "blah blah",
email: "blah blah",
UserComment:"blah blah"
}
});
});
</script>
しかし、[送信]ボタンをクリックしても何も起こりません。
ここで入手可能:http://tinkerbin.com/wRh09opb