jQuery datepicker在IE8中有问题吗? [英] jQuery datepicker having trouble in IE8?
问题描述
这是我的原始问题和来源代码
我将datepicker更新为jQuery UI Datepicker 1.8.11 ...仍然在IE 8中不起作用!日期选择器弹出很好,但没有事件触发。我的意思是没有点击...没有发生任何事情...
任何想法?
嘿,我不知道你是否已经解决了这个问题,但问题是任何附加的属性。特别是如果你使用的是:
yearRange:'-100:+10'
例如...
这是您如何解决问题:从 http://satish.name/?p=19
jQuery datepicker为IE中的DOM元素添加了一个新属性。如果您尝试从现有元素动态添加新的DOM元素,则datepicker将不会在IE中运行,因为新添加的DOM元素引用了旧的jQuery属性。解决这个问题的一种方法是删除属性,然后在元素上实例化datepicker类。请参阅以下代码以获取修补程序。
// newDiv是带有innerHTML
的新添加的dom元素jQuery( #newDiv)。find(。datePicker)。each(function(){
//删除jquery添加的属性,因为这是导致动态
//添加DOM elem引用旧的DOM元素被复制
if(jQuery.browser.msie){
var jqaddedattr;
jQuery(this.attributes).each(function(){
if(this.name。搜索(/ jQuery /)!= -1){
jqaddedattr = this;
}
});
if(jqaddedattr){
jQuery(this) removeAttr(jqaddedattr.name);
}
}
jQuery(this).datepicker({yearRange:'-100:+10',changeFirstDay:false})val() .trigger('change');
})
欢呼
i did see a couple of similar threads, but later they turned out to be different issues...mine seems a browser specific problem surely because my datepicker works fine in Firefox, but certainly not in IE8. Here is my original problem and the source code
I updated my datepicker to jQuery UI Datepicker 1.8.11...still it just doesn't work in IE 8! The date-picker pops up just fine, but no event fires from it. I mean no click...nothing happens...
Any ideas?
Hey I don't know if you have solved that problem yet, however the problem is with any added attributes. Especially if you are using:
yearRange: '-100:+10'
for example ...
This is how you resolve the issue: copied from http://satish.name/?p=19
jQuery datepicker adds a new attribute to the DOM element in IE. if you try to add a new DOM element dynamically copying from an existing element the datepicker will not work in IE as the newly added DOM element refers to the old jQuery attribute. One way to fix this is to delete the attribute and then instantiate the datepicker class on the element. See the following code for the fix.
//newDiv is the new added dom element with innerHTML
jQuery("#newDiv").find(".datePicker").each(function() {
//removing jquery added attribute as this is causing the dynamically
// added DOM elem referring old DOM element from it is copied.
if (jQuery.browser.msie) {
var jqaddedattr;
jQuery(this.attributes).each(function() {
if (this.name.search(/jQuery/) != -1) {
jqaddedattr = this;
}
});
if (jqaddedattr) {
jQuery(this).removeAttr(jqaddedattr.name);
}
}
jQuery(this).datepicker({yearRange: '-100:+10', changeFirstDay:false}).val("").trigger('change');
})
cheers
这篇关于jQuery datepicker在IE8中有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!