setAttribute 与 class冲突解决

2019-12-26,,,,

假设,我们要使用setAttribute来改变一个dom的class时,应该如何写?
   1. setAttribute("class","red")
   2. setAttribute("className","red")

答案是:
  选项1. 在firefox下使用
  选项2. 在IE下使用

如果在IE下给DOM setAttribute("class") 使用IE Developer看结构会发现,DOM上面显示了两个class出来... 原来IE是把自定义的class和系统的class是区分开的。- -b

您可能感兴趣的文章:

  • js setattribute批量设置css样式
  • javascript setAttribute, getAttribute 在不同浏览器上的不同表现
  • IE6、IE7中setAttribute不支持class/for/rowspan/colspan等属性
  • JS getAttribute和setAttribute(取得和设置属性)的使用介绍
  • JavaScript中setAttribute用法介绍
  • JavaScript的setAttribute兼容性问题解决方法
  • javascript中setAttribute()函数使用方法及兼容性

《setAttribute 与 class冲突解决.doc》

下载本文的Word格式文档,以方便收藏与打印。