代码日记 | 小叉 | 2010年11月24日
jQuery中列出setAttribute设置属性时,在IE浏览器与其他浏览器的命名区别列表。
标准浏览器 | IE浏览器 |
---|---|
acceptcharset | acceptCharset |
accesskey | accessKey |
allowtransparency | allowTransparency |
bgcolor | bgColor |
cellpadding | cellSpacing |
cellspacing | cellPadding |
class | className |
colspan | colSpan |
checked | defaultChecked |
selected | defaultSelected |
for | htmlFor |
frameborder | frameBorder |
hspace | hSpace |
longdesc | longDesc |
maxlength | maxLength |
marginwidth | marginWidth |
marginheight | marginHeight |
noresize | noResize |
noshade | noShade |
readonly | readOnly |
rowspan | rowSpan |
tabindex | tabIndex |
valign | vAlign |
vspace | vSpace |
测试浏览器列表:
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.各个属性 ,逐一进行设置。
参考了来源中的介绍,以及亲身实验。
这里是小叉试验场的简版,请到正式版参与评论