Firefox兼容性问题

来源:互联网 发布:张子萱的淘宝店 编辑:程序博客网 时间:2024/06/16 01:33

1、firefox不支持innerText,outerText,outerHTML

解决思路:a)用innerHTML替换innerText

    b)为Firefox扩展innerText属性,详细参考:Firefox 不支持 DOM 对象的 outerHTML、innerText、outerText 属性(http://www.w3help.org/zh-cn/causes/SD9017)


2、firefox不支持onfocusin,onfocusout

参考:http://help.dottoro.com/ljggspvo.php

http://stackoverflow.com/questions/13516931/prevent-cursor-moving-on-text-input


 

Instead of onfocus rather use onfocusin, that'll make your code to work.

EDIT

I just realized, that there is no focusin in Firefox. Hence you need something heavier.

The script:

function changeValueOnFocus (e, elm) {        elm = elm || this;        elm.value = 1234;        return;  }window.onload = function () {    if (window.onfocusin === undefined) {        document.getElementById('someinput').addEventListener('focus', changeValueOnFocus, false);    }    return;}

and for input you'll need an id:

<input id="someinput" maxlength="5" onfocusin="changeValueOnFocus(event, this);" type="text" />

Now this supposed to be a cross-browser solution.


accepte3


3、firefox不支持document.all

在对radio input进行操作时,会用到document.all来选择某个值,比如:

document.all["carType"][0].checked = true;

但是在firefox里不支持document.all,就可以用getElementsByName等来代替:

if (document.all) {    document.all["carType"][0].checked = true;    } else    document.getElementsByName("carType")[0].checked = true;