Heim  >  Artikel  >  Web-Frontend  >  FF IE兼容性的修改小结_javascript技巧

FF IE兼容性的修改小结_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:47:19875Durchsuche

1.html 标签如果用 $(id) 或者 getElementById 这两个方法取值时,要给该标签加上 id 的属性, IE 、 FF 才兼容。如 $(mobile): 如果填 写 mobile 的 input 没有 id 属性在 FF 中会报这个变量 undefined ;
2. 取 form 表单的某个标签对象,如果要 IE 、 FF 兼容要把 formMain.item 改为 document.formName.item 。
如 form1.webUrl 改为 document.form1.webUrl 。
如果 form 作为一个参数传给某个函数,也要加上 "document.", 如 search(formMain) 改为 search(document.formMain)
3. 取 html 的自定义属性用 obj.attributeName 改为 obj.getAttribute("attributeName") 取则 IE 、 FF 兼容;非自定义属性仍可以按照
obj.attributeName 取。
如: 这个标签中的 checkValue 属性为自定义属性,要用 obj.getAttribute("checkValue") 取, IE 、 FF 才兼容,其他属性如 type 属性则仍然可以用 obj.type 取
4.eval 函数,在 FF 和 IE 中使用不一样 , 在 FF 中用“ + ”连接成的一个可执行语句作为 eval 的参数时,不能执行而在 IE 中可以。遇到 要用 eval 时,尽量找别的方法代替。
如: eval("msg_" + textbox.name+ “ .className='wrong' ”) ;
"msg_" + textbox.name+ “ .className='wrong' ”这句话作为 eval 的参数在 IE 中能执行,在 FF 中执行时报 "msg_" + textbox.name 连接得到的空间名 undefined ,不能执行, 要修改为:
document.getElementById("msg_" + textbox.name).className='wrong';
5. 样式中的 display 的属性 block ,在 FF 中如果遇到异常可以变为空;如 item.style.display="block" 可以改为 item.style.display=""
如 $("divType4").style.display="block";
改为 $("divType4").style.display="";
6. 再添加一个: label 在 FF 中好像跟 IE 不一样:比如说以下代码:

成人
td>
这样写在 FF 中输入时儿童的光标总是跑到成人那里去, IE 中不会,而这样写就不会:
成人
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn