zoukankan      html  css  js  c++  java
  • 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!); }

  • 相关阅读:
    clound R
    ubuntu 下安装查看pdf的工具
    统计门户
    neusoft 东软
    一位做数据分析的老师的blog
    ubuntu 下安装查看pdf的工具
    R语言矩阵转置
    取经难,取真经更难。
    R function
    只针对中英文混合分词的中文分词器
  • 原文地址:https://www.cnblogs.com/dunken/p/4401699.html
Copyright © 2011-2022 走看看