我在使用 jQuery Validation 插件和 Internet Explorer 时遇到问题。基本上,在页面加载时会显示“请输入有效的电子邮件地址”错误消息,尽管所有验证都正常工作,但在用户输入任何数据之前出现是相当难看的。
如果我删除电子邮件类并只填写必填字段没有问题,但我希望它验证电子邮件地址。
我在 IE7/8/9 中遇到了这个问题
这是我的代码:
//Form Validation
$(document).ready(function(){
$("#rsvpForm").validate({
rules: {
// simple rule, converted to {required:true}
attendance: "required",
firstname_main: "required",
lastname_main: "required",
// compound rule
email: {
required: true,
email: true
},
total_guests: {
required: "#attendance:checked"
},
firstname_partner: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '2' || $("input:radio[name='total_guests']:checked").val() == '3' || $("input:radio[name='total_guests']:checked").val() == '4'
}
},
lastname_partner: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '2' || $("input:radio[name='total_guests']:checked").val() == '3' || $("input:radio[name='total_guests']:checked").val() == '4'
}
},
firstname_child1: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '3' || $("input:radio[name='total_guests']:checked").val() == '4'
}
},
lastname_child1: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '3' || $("input:radio[name='total_guests']:checked").val() == '4'
}
},
firstname_child2: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '4'
}
},
lastname_child2: {
required: function(element) {
return $("input:radio[name='total_guests']:checked").val() == '4'
}
},
}
});
jQuery.extend(jQuery.validator.messages, {
required: 'Required',
});
});
// Submit Handler
$(document).ready(function() {
$('#rsvpForm').ajaxForm({
target: '#content',
url: 'components/process-form-data.php'
});
});
这些是我的标题链接:
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script type="text/javascript" src="../javascript.js"></script>
表单 HTML:
<form method="post" action="components/process-form-data.php" id="rsvpForm">
<fieldset>
<label for="attendance">Will you be attending the wedding? <em>*</em></label>
<div class="radioBtns">
<input class="signUp" type="radio" value="Yes" name="attendance" id="attendance" />
<label class="signUp">Yes</label>
<input class="signUp" type="radio" value="No" name="attendance" />
<label class="signUp">No</label>
</div>
</fieldset>
<h2>Main Guest</h2>
<fieldset>
<label for="firstname_main" class="standard">First name<em>*</em> :</label>
<input type="text" name="firstname_main" id="firstname_main" placeholder="First name" />
</fieldset>
<fieldset>
<label for="lastname_main" class="standard">Last name<em>*</em> :</label>
<input type="text" name="lastname_main" id="lastname_main" placeholder="Last name" />
</fieldset>
<fieldset>
<label for="email" class="standard">Email<em>*</em> :</label>
<input type="text" name="email" id="email" placeholder="Email" />
</fieldset>
<div id="guests">
<fieldset class="wideField">
<label for="total_guests">Will you be bringing a partner and/or young children? <em>*</em></label>
<div class="radioBtns">
<input class="signUp" type="radio" value="1" name="total_guests" id="total_guests" />
<label class="signUp">No</label>
<input class="signUp" type="radio" value="2" name="total_guests" />
<label class="signUp">Just Partner</label>
<input class="signUp" type="radio" value="3" name="total_guests" />
<label class="signUp">Partner + 1 young child</label>
<input class="signUp" type="radio" value="4" name="total_guests" />
<label class="signUp">Partner + 2 young children</label>
</div>
</fieldset>
</div>
<div id="partnerDetails" style="display:none;">
<h2>Partner Details</h2>
<fieldset>
<label for="firstname_partner" class="standard">First name<em>*</em> :</label>
<input type="text" name="firstname_partner" id="firstname_partner" placeholder="First name" />
</fieldset>
<fieldset>
<label for="lastname_partner" class="standard">Last name<em>*</em> :</label>
<input type="text" name="lastname_partner" id="lastname_partner" placeholder="Last name" />
</fieldset>
</div>
<div id="childDetails" style="display:none;">
<h2>Child Details</h2>
<fieldset>
<label for="firstname_child1" class="standard">First name<em>*</em> :</label>
<input type="text" name="firstname_child1" id="firstname_child1" placeholder="First name" />
</fieldset>
<fieldset>
<label for="lastname_child1" class="standard">Last name<em>*</em> :</label>
<input type="text" name="lastname_child1" id="lastname_child1" placeholder="Last name" />
</fieldset>
</div>
<div id="secondChildDetails" style="display:none;">
<fieldset>
<label for="firstname_child2" class="standard">First name<em>*</em> :</label>
<input type="text" name="firstname_child2" id="firstname_child2" placeholder="First name" />
</fieldset>
<fieldset>
<label for="lastname_child2" class="standard">Last name<em>*</em> :</label>
<input type="text" name="lastname_child2" id="lastname_child2" placeholder="Last name" />
</fieldset>
</div>
<div id="diet">
<fieldset class="wideField">
<label for="dietaryRequirements">Do any of your guests have special dietary requirements :</label>
<textarea cols="55" rows="8" name="dietaryRequirements" id="dietaryRequirements"></textarea>
</fieldset>
</div>
<input id="submit_btn" input="" type="submit" value="Submit RSVP" class="btn" />
</form>