js document.createElement浏览器兼容处理
来源:互联网 发布:vr视频剪辑制作软件 编辑:程序博客网 时间:2024/05/16 09:45
js document.createElement浏览器兼容处理
1:innerText
IE支持,FIREFOX不支持解决办法:用innerHTML,2种浏览器都识别innerHTML
2:document.createElement_x
document.appendChild
在往表里插入行时
FIREFOX支持,IE不支持
解决办法:把行插入到TBODY中,不要直接插入到表
3:setAttribute('style','color:red;')
FIREFOX 支持(除了IE,现在所有浏览器都支持),IE不支持
解决办法:不用setAttribute('style','color:red')
而用object.style.cssText = 'color:red;'(这写法也有例外)
最好的办法是上面种方法都用上,万无一失 ^_^
4:class
setAttribute('class','styleClass')
FIREFOX 支持,IE不支持(指定属性名为CLASS,IE不会设置元素的CLASS属性,相反只使用SETATTRIBUTE时IE自动识别CLASSNAME属性)
解决办法:
setAttribute('className','styleClass')
2 种都用上
5:用setAttribute设置事件
var obj = document.getElementByIdx_x('objId');
obj.setAttribute('onclick','funcitonname();');
FIREFOX 支持,IE不支持
解决办法:
IE中必须用点记法来引用所需的事件处理程序,并且要用赋予匿名函数
如下:
var obj = document.getElementByIdx_x('objId');
obj.onclick=function(){fucntionname();};
这种方法所有浏览器都支持
6:建立单选钮
IE以外的浏览器
var rdo = document.createElement_x('input');
rdo.setAttribute('type','radio');
rdo.setAttribute('name','radiobtn');
rdo.setAttribute('value','checked');
IE:
var rdo =document.createElement_x("<input type='radio' name='radiobtn' value='checked'>");
解决办法:
这一点区别和前面的都不一样。这次完全不同,所以找不到共同的办法来解决,那么只有IF-ELSE了
万幸的是,IE可以识别出document的uniqueID属性,别的浏览器都不可以识别出这一属性。问题解决。
0:共同的一些技巧
在动态建立INPUT型输入元素时,一般是先加入,在设置TYPE。这就有可能出错
好习惯:var btn = document.createElement_x('input');
btn.setAttribut('type','button');
document.getElementByIdx_x('formId').appendChild(btn);
GWT-EXT2.0+struts2+hibernate+ejb++spring
0 0
- js document.createElement浏览器兼容处理
- document.createElement IE 兼容
- js document.createElement()
- js document.createElement
- js document.createElement()的用法
- js、document.createElement()的用法
- 动态加载js文件 document.createElement
- JS document.createElement 动态添加表
- JS中document.createElement()的用法
- js document.createElement()的用法 (转)
- JS中document.createElement()用法及注意事项
- js document.createElement()的用法 (转)
- 【转】JS写图层方法.document.createElement("div")
- JS中document.createElement()的用法
- JS中document.createElement()的用法
- document.createElement()
- document.createElement()
- Document.createElement()
- ServletContext总结
- 在struts1中使用DispatchAction对应多个ActionForm,实现写一个Action实现增删改查操作---一个Action处理多个操作的能力
- 提供大数据分析服务以及机器学习API的公司
- 第11周-深入了解继承派生的机制
- 个人PHP学习笔记(五)--面向对象的程序设计
- js document.createElement浏览器兼容处理
- Nginx配置文件详细说明
- Activity生命周期
- PMP计算公式
- 添加、删除数据文件个数
- 基于帧间频域分析的视频篡改检测
- Installing FusionPBX 3.2 on CentOS 6.5 and Mysql
- SQL中存储过程和函数的区别
- Debug Hacks 深入调试的技术和工具(一) 热身准备