當我提交與空字段的形式我得到對話框成功消息。相反,我想在對話框中顯示錯誤信息。請幫我找到解決方案。jQuery的空場驗證
我的HTML代碼:
<form id="booking" action="" method="post">
First Name:<input type="text" id="firstName" name="firstName" maxlength="30" /><br/>
Last Name:<input type="text" id="lastName" name="lastName" maxlength="30"/><br/>
Contact:<input type="text" id="contact" name="contact" maxlength="15"/><br/>
Email: <input type="text" id="email" name="email" maxlength="30"/><br/>
<input id="save" type="button" value="Save" />
</form>
<div id="dialog"></div>
jQuery代碼:
$('#save').click(function(){
if(('#firstName').length==0 && ('#lastName').length==0 && ('#contact').length==0 && ('#email').length==0){
$('#dialog').attr('title','Error').text('All fields are required').dialog();
}else{
$('#dialog').attr('title','Success').text('Success').dialog();
}
});
我會去了解一下'jQuery的validate'插件。 –