setAttribute 的兼容性

返回列表

代码日记 | 小叉 | 2010年11月24日

jQuery中列出setAttribute设置属性时,在IE浏览器与其他浏览器的命名区别列表。

标准浏览器IE浏览器
acceptcharsetacceptCharset
accesskeyaccessKey
allowtransparency allowTransparency
bgcolor bgColor
cellpaddingcellSpacing 
cellspacing cellPadding 
class className
colspan colSpan
checked defaultChecked
selected defaultSelected
forhtmlFor
frameborder frameBorder
hspace hSpace
longdesc longDesc 
maxlengthmaxLength
marginwidthmarginWidth
marginheightmarginHeight
noresizenoResize 
noshadenoShade
readonlyreadOnly
rowspanrowSpan
tabindextabIndex
valignvAlign
vspacevSpace

测试浏览器列表:

IE8、IE7、火狐3.6、Chrome7、Opeara10

 

class和className兼容方法:

object.setAttribute("class","content")

在IE8、Chrome、火狐、Opera10中都能设置成功;但是在IE7下无法设置

object.setAttribute("className","content")

只有IE7能设置成功,但是其他浏览器均无法设置。

兼容方法:

使用 object.className ="content"

 

style和cssText兼容方法:

object.setAttribute("style","position:absolute;left:10px;top:10px;")

在IE8、Chrome、火狐、Opera10中都能设置成功;但是在IE7下无法设置

object.setAttribute("cssText","position:absolute;left:10px;top:10px;")

此设置方法,所有浏览器均不支持

兼容方法:

使用 object.style.cssText="position:absolute;left:10px;top:10px;"

或者单独 object.style.各个属性 ,逐一进行设置。

 

参考了来源中的介绍,以及亲身实验。

参考资料
1http://blog.csdn.net/cheng5128/archive/2009/12/01/4917928.aspx

这里是小叉试验场的简版,请到正式版参与评论

下一篇:教你怎么把图标字体(IconFont)转为 PNG

上一篇:南岳衡山游

返回列表