JS中浏览器兼容性问题(亲自实践)

1、new Date().getYear():如果是IE返回的正确的值;如果是FF,返回的是距离1990年的差值

2、现在IE和FF都可以使用eval("idName")来获取ID为idName的对象(原来FF不支持)

3、在IE中不可以使用const来声明值,使用var吧(报错)

4、获取外部CSS属性,FF使用的是document.defaultView.getComputedStyle(element,null).protyName;或者:getComputedStyle(obj,false)[attr],不能识别element.currentStyle.protyName;IE 均可以

function getStyle(obj,attr){
  if(obj.currentStyle){
    return obj.currentStyle[attr];
  }else{
    //return getComputedStyle(obj,false)[attr];
    return document.defaultView.getComputedStyle(obj,null)[attr];
  }
}

5、document.forms("formName");//仅适用于IE

  document.forms["formName"]//IE FF 均可

6、获取父节点:parentElement,parentNode

  其中FF只可以使用parentNode;

7、如果将tr添加到table中,IE67不可以直接添加,必须将其添加到tbody中,其他的可以.

8、在select中的option中,FF不支持innerText。

  如果要是删除其中一个option可以使用:$("sele").options.remove(1);或者$("sele").options[0]=null;

9、IE和FF事件绑定不同:

  IE:attachEvent;FF:addEventListener

10、IE中是srcElement,FF是target

posted @ 2012-09-21 18:11  wcp_spring  阅读(180)  评论(0)    收藏  举报