getAttribute和setAttribute操作class

日期:2009-01-31    阅读:92   分类:Javascript

在web开发中,经常会用getAttribute和setAttribute操作元素属性,这使得我们在实际应用中更加的方便和灵活。

但在写支持多皮肤的无限极菜单的时候,发现些问题:

getAttribute和setAttribute在非ie浏览器中都能正常工作,在ie中却并不能识别,但简单测试后,发现ie支持obj.getAttribute("className")和obj.className,为什么会这样就不太清楚,难道class在ie中有特殊意义?

不过解决方案还是很简单的,只要在使用的时候做下判断,看下 obj.getAttribute("class")是否存在,否则取obj.getAttribute("className")。

当然你也可以直接使用obj.className,这样在各个浏览器也能很好的运行。


本页链接: http://www.scriptlover.com/static/362-attribute-class

标签:

相关文章

网友评论

#1: 2012-1-26 12:37:00 by Laticiaajaba#hotmail.com

An intelligent point of view, well exprseesd! Thanks!

Leave a comment

 required

 required (Not published)

 required