日期:2014-05-16  浏览次数:20362 次

firefox与ie 的javascript区别

Document.form.item 问题

现有问题:

现有代码中存在许多 document.formName.item("itemName") 这样的语句,不能在 firefox下运行。

解决方法:

改用 document.formName.elements["elementName"]。

集合类对象问题

现有问题:

现有代码中许多集合类对象取用时使用 (),IE 能接受,firefox 不能。

解决方法:

改用 [] 作为下标运算。如:document.forms("formName") 改为 document.forms["formName"]。

又如:document.getElementsByName("inputName")(1) 改为 document.getElementsByName("inputName")[1]

window.event

现有问题:

使用 window.event 无法在 firefox上运行

解决方法:

MF的 event 只能在事件发生的现场使用,此问题暂无法解决。可以这样变通:

原代码(可在IE中运行):
<input?type="button"?name="someButton"?value="提交"?onclick="javascript:gotoSubmit()"/>

????alert(window.event);????
//?use?window.event
????
}
</script>
新代码(可在IE和MF中运行):
<input?type="button"?name="someButton"?value="提交"?onclick="javascript:gotoSubmit(event)"/>

????????alert(evt);?????????????
//?use?evt
????????
????}
</script>

此外,如果新代码中第一行不改,与老代码一样的话(即 gotoSubmit 调用没有给参数),则仍然只能在IE中运行,但不会出错。所以,这种方案 tpl 部