1
下面的jquery腳本iam使用。但是這在firefox和chrome中都可以使用,但是在IE中不能使用。jQuery的表單在IE提交沒有驗證之前提交
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function() {
//alert("submitted!");
debug: false;
form.submit();
}
});;
</script>
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("mobilecheck", function(value, element) {
return this.optional(element) || /^[0-9]+$/i.test(value);
}, "mobile number must contain only numbers");
$.validator.addMethod("namecheck", function(value, element) {
return this.optional(element) || /^[a-z\s]+$/i.test(value);
}, "User Name must contain only letters");
$("#myform").validate({
rules: {
fullname:{ required : true , namecheck :true},
mobile:{ required : true, mobilecheck :true },
city: { required : true},
locality: { required : true},
email: {
required: true,
email: true
},
jobcity: { required : true} ,
hometown: { required : true} ,
},
messages: {
fullname:{
required: "Please enter your fullname" ,
namecheck: " Full Name must contain only alphabets<br/>"
},
mobile: {
required: "Please enter mobile number",
mobilecheck: "Mobile number must contain only numbers "
},
city: "Please enter your current city" ,
jobcity:"please select city" ,
locality:"please enter locality where you are staying",
email: {
email:"Please enter a valid email address",
required:"please enter email address"
},
},
errorElement: "div"
});
});
</script>
我的表單代碼是
<form id="myform" method="post" class="register" >
<ul>
<li>
<label for="fullname">Full Name</label>
<input id="fullname" name="fullname" class="required namecheck" size="20" style="width:180px"/>
</li>
<li><label for="email">Email</label>
<input id="email" name="email" class="required email" size="20" style="width:180px" />
</li>
<li>
<label for="mobile">Mobile</label>
<input id="mobile" name="mobile" class ="required mobilecheck" size="20" style="width:180px" maxlength="10"/>
<span id="msgbox" style="display:none"></span>
</li>
<li>
<label for="qualification">Qualification</label>
<input id="qualification" name="qualification" class ="required " size="20" style="width:180px" maxlength="10"/>
<span id="msgbox" style="display:none"></span>
</li>
<li>
<label for="hometown">Home Town</label>
<input id="hometown" name="hometown" class="required" size="20" style="width:180px"/>
</li>
<li>
<label for="city">Current City</label>
<input id="city" name="city" size="20" class="required" style="width:180px"/>
</li>
<li>
<label for="locality">Locality/Neighborhood/Area</label>
<input id="locality" name="locality" class="required" size="20" style="width:180px"/>
</li>
<li>
<label for="jobcity" >Preferred Location for Interview</label>
<select name="jobcity" id="jobcity" clas="required">
<option value=""> -- please select-- </option>
<option value="Bangalore"> Bangalore</option>
<option value="Chennai">Chennai</option>
<option value="Gurgaon">Gurgaon/Noida/Delhi</option>
<option value="Hyderabad"> Hyderabad</option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
</select></br>
</li>
</ul>
<div style="text-align:center;margin-top:5px;padding-bottom:10px">
<input name="hidden" type="hidden" value="hidden"/>
<input class="blue1 button1" id="#submit" type="submit" value="Submit"/>
</div>
,當我在IE提交表單,它沒有驗證,但提交表單。在Chrome中,IE .jquery在提交之前驗證表單。
和i。從代碼
請告訴我們什麼是在Chrome中,而不是在IE中。 – evasilchenko