当我提交带有空字段的表单时,我会在对话框中收到成功消息。相反,我想在对话框中显示错误消息。请帮助我找到解决方案。
我的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();
}
});