Jquery日期规则在firefox和IE中不起作用 [英] Jquery date rule not working in firefox and IE
问题描述
我用jquery日期规则渲染了普通文本。日期规则在chrome中正常工作但在Firefox和IE中无法正常工作。请参阅我的代码块。
< form id =myform>
< input id =datepicktype =textname =datepick/>
< input type =submitid =ValidateDate/>
< / form>
$(#myform)。验证({
规则:{
datepick:{
date:MM / dd / yyyy
}
},
条消息:{
datepick:{
date:Give MM / dd / yyyy format
}
}
});
$('#datepick')。keyup(function(){
$(#ValidateDate)。submit();
});
< / script>
当我输入 12 / 3err / 3001 时,它会在所有浏览器中抛出错误
当我输入 12/234/2333 时,它会在firefox和IE中抛出错误chrome。
另外我想分享一个信息。
在Firefox中:
请帮我解决这个问题.....
谢谢,
Gobalakrishnan
此问题是由于浏览器之间的日期解析行为差异造成的。您可以看到以下内容。
Chrome
新日期(92 / 12/2015)
- 无效日期
FireFox
新日期(92/12/2015)
- 日期{Sun Jun 07 1998 00:00:00 GMT + 0530(印度标准时间)}
date
规则仅根据输入的日期值检查格式,因此验证在FF中成功。
因为@SomekidwithHTML建议您可以使用 dateIso
,它将根据ISO日期标准检查日期或实施根据您的需要进行自定义验证。
http://jqueryvalidation.org/jQuery.validator.addMethod/
I have rendered the normal text with jquery date rule. The date rule working fine in chrome but not working in the Firefox and IE . please see my code block.
<form id="myform">
<input id="datepick" type="text" name ="datepick"/>
<input type="submit" id="ValidateDate" />
</form>
$("#myform").validate({
rules: {
datepick:{
date:"MM/dd/yyyy"
}
},
messages: {
datepick:{
date:"Give MM/dd/yyyy format"
}
}
});
$('#datepick').keyup(function () {
$("#ValidateDate").submit();
});
</script>
when i type 12/3err/3001 it throws error in all browser
when i type 12/234/2333 it throws error chrome not in firefox and IE.
Additionally i want to share one information.
http://jqueryvalidation.org/date-method/
In the above link jQuery validation is not working properly in Mozilla , IE browser even for a normal textbox.
please type the 22/233/2222 value in the above jquery link sample then you can find the below output variation
In chrome :
In Firefox:
Please help me to resolve this.....
Thanks,
Gobalakrishnan
This issue is due to the date parsing behavior difference between the browsers. You can see the below.
Chrome
new Date("92/12/2015") - Invalid Date
FireFox
new Date("92/12/2015") - Date {Sun Jun 07 1998 00:00:00 GMT+0530 (India Standard Time)}
The date
rule will only check for format based on inputted date value and hence the validation succeeded in FF.
So as @SomekidwithHTML proposed you can use the dateIso
which will check the date against ISO date standards or implement your our custom validation as per your need.
http://jqueryvalidation.org/jQuery.validator.addMethod/
这篇关于Jquery日期规则在firefox和IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!