When Element add attribute by the method "setAttribute",It can't work in IE
来源:互联网 发布:阳光网络伴我成长图片 编辑:程序博客网 时间:2024/06/10 08:52
今天使用Javascript 操纵页面元素,想给指定的 Element 添加一些Attribute,使用
Ele.setAttribute("class", "tdbg");
Ele.setAttribute("onclick", "test");
结果在IE里面查看 元素的 Text 看到代码里面明明有了这些属性的设置 怎么一个都没起作用,但是在 mozilla里面却是对的,查看了相关文档,
原来 两句话在 IE 里面都错了,但是错的不一样。
第一句错的地方是 在IE里面 class 应为className
第二句是因为 在IE里面 onclick 是一个 Event,不能用添加 Attribute 的方法 setAttribute 来设定,
有两种方法可以使用:
1.使用DOM的 添加 Event 的方法, Ele.attachEvent('ondblclick',testonclick);
2.elmt.onXXX = function() { return false; }
通过这两种方法都可以添加 Element 的事件,在 Mozilla 中也可正常使用
注意: row.attachEvent('ondblclick',testonclick);里面的事件都应为小写 如"ondblclick'" 像 "onDblClick" 这样是不对的。
参考文章:
"setAttribute does not work when used with the style attribute " at www.quirksmode.org
- When Element add attribute by the method "setAttribute",It can't work in IE
- when the preview menu is diabled in BO, you can add this setting to enabled it
- White space is required before the attribute type in the declaration of attribute "t" for element "b
- Magento can't checkout and add product to cart in IE and Chrome
- ADB can't work
- OC sign-in can't work's solution
- The VS7 Debugger doesn’t work. What can I do?
- The Simulator can't be launched because it is already in use.
- Xcode The Simulator can't be launched because it is already in use .
- The Simulator can't be launched because it is already in use.
- Xcode The Simulator can't be launched because it is already in use .
- ios The Simulator can't be launched because it is already in use.
- IIS ERROR about SP:The process can't access the file because it is being used by another process
- mysql 触发器的问题 Can't update table 'tbl' in stored function/trigger because it is already used by state
- Can't update table 'psxt_user' in stored function/trigger because it is already used by statement wh
- Can't use method return value in write context
- iOS “[App] if we're in the real pre-commit handler we can't actually add any new fences due
- iOS “[App] if we're in the real pre-commit handler we can't actually add any new fences due
- 树型结构数据在关系数据库中用链式存储相关查询实现
- 新年快乐
- tomcat插件安装
- 好久都没有来这个我们共同交流的地方了
- 1002 。
- When Element add attribute by the method "setAttribute",It can't work in IE
- ORACLE锁的管理
- 大家一起来破这个JSP.
- JAVA5 学习(1)
- 平静
- JAVA5 学习(2)
- JAVA5 学习(3)
- Photoshop入门与进阶实例:3.3 乳胶漆纹理效果
- Photoshop入门与进阶实例:3.4 碎石岩纹理