为什么链接不工作在IE8 / 9
Why does chaining not work in IE8 / 9
为什么这样做:
el = document.getElementById('STR');
if( el ){
el.checked = true;
el2 = el.cloneNode(false);
el.parentNode.insertBefore(el2, el);
el2.setAttribute('id','');
el2.setAttribute('disabled','disabled');
el2.removeAttribute('name');
el.removeAttribute("disabled");
el.style.display="none";
}
但这不是:
el = document.getElementById('STR');
if( el ){
el.checked = true;
el2 = el.cloneNode(false);
el.parentNode.insertBefore(el2, el);
el2.setAttribute('id','');
el2.setAttribute('disabled','disabled').removeAttribute('name');
el.removeAttribute("disabled");
el.style.display="none";
}
在Firefox/Chrome中,最后一段代码可以完美地工作。
这在我所知道的任何浏览器中实际上都不起作用。DOM的"setAttribute()"函数在Firefox和Chrome(可能也包括IE)中返回undefined
。
如果你想的话,你可以在JavaScript中实现"链接"代码风格,但它需要某种框架来显式地实现它。DOM方法通常不是这样工作的。
相关文章:
- IE8更改文本区域上的事件侦听器不工作
- window.onbeforeunload在IE8中不触发(在Firefox,Chrome和Safari中工作正常)
- $('body').on('blur')在IE8中工作不好
- window.location重定向没有'我不在IE8上工作
- addEventListener没有'不能在IE中工作(在IE8中测试)
- Requirejs和主干应用程序,不能在IE8中工作
- 无法在 IE 9 中传递此运算符的值,而它在 IE7 和 IE8 中工作正常
- Request.UrlReferrer在IE8中无法正常工作,并且工作正常IE9
- 不触发 OnClick 事件 IE8,但在 Firefox 中工作正常
- 如何优化我的jQuery以始终在IE8中工作,目前它被击中和错过
- 获取尾随逗号(在JavaScript中)在IE7 / IE8中工作
- FormData ajax 上传 IE8 -> 替代品及其工作原理
- jquery设置隐藏的输入值在IE7和IE8中未按预期工作
- 代码不'我不在IE8工作
- IE7中没有填充mootools中的动态下拉列表.IE8工作良好
- 梅森不在IE8工作
- Youtube iframe API调用以播放视频/pauseVideo don'我不在IE8工作
- 映射/设置与ie8工作的实现
- window.attachEvent没有'我似乎在IE8工作
- Fancybox Overlay Helper'我不在IE8工作