JavaScript's IE and Firefox compatibility assembly
Author: yaosansi Date: 2006-11-14
1. Document.form.item question
(1) Existing problems:
There are many Document.formName.item ("itemname") statements in existing code that cannot be run under MF
(2) Solution:
Switch to document.formname.elements["ElementName"]
(3) Other
See also 2
2. Collection Class object problem
(1) Existing problems:
Many collection class objects in existing code use (), IE can accept, MF cannot.
(2) Solution:
Use [] as the subscript operation instead. For example: Document.forms ("FormName") changed to document.forms["FormName"].
Also as follows: Document.getelementsbyname ("InputName") (1) Changed to Document.getelementsbyname ("InputName") [1]
(3) Other
3. window.event
(1) Existing problems:
Unable to run on MF using window.event
(2) Solution:
MF event can only be used at the scene of the incident, this problem can not be resolved. You can do this:
Original code (can run in IE):
<input type= "button" Name= "Somebutton" value= "Submit" onclick= "Javascript:gotosubmit ()"/>
...
<script language= "JavaScript" >
function Gotosubmit () {
...
alert (window.event); Use window.event
...
}
</script>
New code (can run in IE and MF):
<input type= "button" Name= "Somebutton" value= "Submit" onclick= "Javascript:gotosubmit" (event)/>
...
<script language= "JavaScript" >
function Gotosubmit (evt) {
EVT = evt? EVT: (window.event window.event:null);
...
alert (EVT); Use EVT
...
}
</script>
In addition, if the first line in the new code does not change, the same as the old code (that is, the gotosubmit call does not give the parameter), it still can only run in IE, but not error. Therefore, the TPL part of this scheme is still compatible with the old code.
Add to the original: the object of the event, in IE is window.event.srcElement, in Firefox is Event.target, and in opera both support. Or use examples to illustrate.
Event.srcelement/event.target