setAttribute的兼容性
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.各个属性 ,逐一进行设置。
Firefox和IE的JS兼容性:设置元素style熟悉
在IE下setAttribute设置元素的对象、集合和事件属性都只当成普通属性,起不到原有的作用,但可以直接进行赋值操作,如下:
var cssText = ”font-weight:bold;color:red;”
//下面写法用于firefox类型浏览器
element.setAttribute(“style”,cssText);
//下面写法用于IE类型浏览器
element.style.cssText = cssText;
方法属性等问题
例如:
var bar =
document.getElementById(testbt);
bar.setAttribute(onclick,
javascript:alert('This is a
test!'););
这里利用setAttribute指定e的onclick属性,简单,很好理解。
但是IE不支持,IE并不是不支持setAttribute这个函数,而是不支持用setAttribute设置某些属性,例如对象属性、集合属性、事件属性,也就是说用setAttribute设置style和onclick这些属性在IE中是行不通的。
为达到兼容各种浏览器的效果,可以用点符号法来设置Element的对象属性、集合属性和事件属性。
document.getElementById(testbt).className
= bordercss;
document.getElementById(testbt).style.cssText = color:
#00f;;
document.getElementById(testbt).style.color =
#00f;
document.getElementById(testbt).onclick= function () { alert(This is a
test!); }
setAttribute的兼容性的更多相关文章
- js中setAttribute 的兼容性
js中setAttribute 的兼容性class和className兼容方法: object.setAttribute("class","content") ...
- JS中setAttribute的兼容性问题(摘自leejersey)
class和className兼容方法: object.setAttribute("class","content") 在IE8.Chrome.火狐.Opera ...
- setAttribute一个兼容性问题
前几天工作中遇到一个js问题,本来js就不大会,倒腾了好长时间,并在做弹窗的时候用到了setAttribute,出现了不兼容的问题,在网上查了好多,真是郁闷,看来啥都得学啊. 主要的工作是做一个根据时 ...
- JS setAttribute兼容
问题和表现: 最近实践中遇到的问题,setAttribute()设置在IE7中,无法设置style等属性.这样就对设置样式带了很大的困扰,例如绑定点击事件来隐藏元素,setAttribute(”sty ...
- JavaScript 的setAttribute兼容性解决
setAttribute各个浏览器都支持,但在IE7以下版本中,有些属性值还是有差异的,比如 obj.setAttribute("class","classname&qu ...
- setAttribute的浏览器兼容性(转)
1.element要用getElementById or ByTagName来得到, 2.setAttribute("class", vName)中class是指改变"c ...
- setAttribute的浏览器兼容性
1.element要用getElementById 或者是ByTagName来得到 2.setAttribute("class", vName)中class是指改变"cl ...
- SVG中 transform矩阵遇到的兼容性问题
SVG transform矩阵遇到的兼容性问题.在chrome.safari.火狐.360极速浏览器上都正常显示的图,在手机端就不行啊!!! 先上图. 图1 PC端浏览器 图2 iPho ...
- js在IE和FF下的兼容性问题
本文出自前端档案,以作学习参考之用.自己也补充了一些内容 长久以来JavaScript兼容性一直是Web开发者的一个主要问题.在正式规范.事实标准以及各种实现之间的存在的差异让许多开发者日夜煎熬.为此 ...
随机推荐
- MyBatis 基本数据类型条件判断问题
1.判断参数使用:_parameter <select id="findCount" parameterType="int" resultType=&qu ...
- H5加载优化
- RLE行程长度编码压缩算法
在看emWIN的时候看到一个图片压缩的算法可以有效的对二值图(简单的2中颜色或者更多)进行压缩,压缩的效果可以节省空间而且不丢失信息! 特点 一种压缩过的位图文件格式,RLE压缩方案是一种极其成熟的压 ...
- 做环信聊天布局时遇到的问题(UITextView自适应高度和光标位置不正常)
聊天时UITextView发送消息超过最大高度后点击发送按钮同时将文本清空,光标的位置偏离了正常的轨迹.如图 后研究发现UITextView向上滚动的时候,contentOffset.y都会发生改变, ...
- Chapter 2 Open Book——16
By Friday I was perfectly comfortable entering my Biology class, nolonger worried that Edward would ...
- iOS 开发者旅途中的指南针 - LLDB 调试技术
文章转载于:iOS 开发者旅途中的指南针 - LLDB 调试技术 今天给大家介绍的内容,无关乎任何功能性开发技术,但又对开发的效率影响至深,这就是调试技术. 何为调试呢,比如我们用 print 函数在 ...
- [tableView dequeueReusableCellWithIdentifier:CellIdentifier] 后面forIndexPath:indexPath参数的解释
解决以下错误: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'u ...
- 【翻译】Longest Palindromic Substring 最长回文子串
原文地址: http://articles.leetcode.com/2011/11/longest-palindromic-substring-part-i.html 转载请注明出处:http:// ...
- Thinkphp中使用Redis
先确保安装了redis扩展 添加Redis配置 'REDIS_HOST'=>'192.168.0.2', 'REDIS_PORT'=>6379, 其他配置根据自己ThinkPHP版本,找到 ...
- 重启库,提示找不到mysqld
--ledir=/usr/local/mysql/bin 加上server的 directory https://dev.mysql.com/doc/refman/5.5/en/mysqld-s ...