In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to explore the compatibility of IE and Firefox in JavaScript. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Compatibility of IE and Firefox in JavaScript
1.document.formName.item ("itemName") problem
Note: under IE, you can use document.formName.item ("itemName") or document.formName.elements ["elementName"]; under Firefox, you can only use document.formName.elements ["elementName"].
Solution: unified use of document.formName.elements ["elementName"] .Text1:
Document.formName.item ("itemName") document.formName.elements ["elementName"]
two。 Set class object problem
Note: under IE, you can use () or [] to get collection objects; under Firefox, you can only use [] to get collection objects.
Solution: uniformly use [] to get collection class objects.
Text2:
Document.forms ("formName") document.forms ["formName"]
Text3:
Document.getElementsByName ("inputName") (0) document.getElementsByName ("inputName") [0]
3. Custom attribute problem
Description: under IE, you can use the method of getting general attributes to get custom attributes, or you can use getAttribute () to obtain custom attributes; under Firefox, you can only use getAttribute () to get custom attributes.
Solution: get custom attributes uniformly through getAttribute ().
Text4:
Get the value of the custom property directly
Get the value of a custom property through getAttribute ()
4.eval ("idName") problem
Note: under IE, you can use eval ("idName") or getElementById ("idName") to get the HTML object whose id is idName; under Firefox, you can only use getElementById ("idName") to get the HTML object whose id is idName.
Solution: uniformly use getElementById ("idName") to get the HTML object whose id is idName.
Text5:
Eval ("idName") document.getElementById ("itemId")
5. The problem that the variable name is the same as a HTML object ID
Note: under IE, the ID of HTML object can be used directly as a subordinate object variable name of document; under Firefox, you can use the same variable name as HTML object ID; under Firefox, you can use the same variable name; IE cannot.
Solution: use document.getElementById ("idName") instead of document.idName.*** do not take the same variable name of the HTML object ID to reduce errors; when declaring variables, always add var to avoid ambiguity.
6.const problem
Note: under Firefox, you can use the const keyword or var keyword to define constants; under IE, you can only use the var keyword to define constants.
Solution: uniformly use the var keyword to define constants.
7.input.type attribute problem
Note: the input.type attribute under IE is read-only, but the input.type attribute under Firefox is read-write.
8.window.event problem
Note: window.event can only be run under IE, but not under Firefox, because Firefox's event can only be used at the scene of an event.
Solution:
IE:
... FunctiongotoSubmit8_2 (evt) {... Evtevt=evt?evt: (window.event?window.event:null); alert (evt); / / useevt...} script >
9.event.x and event.y problem
Description: under IE, the even object has the XMagy attribute, but no pageX,pageY attribute; under Firefox, the even object has the pageX,pageY attribute, but no XMagy attribute.
Solution: use mX (mX=event.x?event.x:event.pageX;) instead of event.x under IE or event.pageX under Firefox.
10.event.srcElement problem
Description: under IE, even objects have srcElement attributes, but no target attributes; under Firefox, even objects have target attributes, but no srcElement attributes.
Solution: use obj (obj=event.srcElement?event.srcElement:event.target;) instead of event.srcElement under IE or event.target under Firefox.
11._window.location.href problem
Note: under IE or Firefox2.0.x, you can use _ window.location or _ window.location.href;Firefox1.5.x, but only _ window.location.
Solution: use _ window.location instead of _ window.location.href.
twelve。 Modal and modeless window problems
Description: modal and modeless windows can be opened through showModalDialog and showModelessDialog in IE, but not in Firefox.
Solution: open a new window directly using window.open (pageURL,name,parameters).
If you need to pass parameters in the child window back to the parent window, you can use window.opener in the child window to access the parent window. For example: varparWin=window.opener;parWin.document.getElementById ("Aqing") .value = "Aqing"
13.frame problem
Take the following frame as an example:
(1) access the frame object:
IE: use window.frameId or window.frameName to access this frame object.
Firefox: only window.frameName can be used to access this frame object.
In addition, you can use window.document.getElementById ("frameId") to access this frame object in both IE and Firefox.
(2) switch frame content:
You can use window.document.getElementById ("testFrame") .src = "xxx.html" or window.frameName.location= "xxx.html" to switch the content of frame in both IE and Firefox.
If you need to pass parameters from frame back to the parent window, you can use parent in frme to access the parent window. For example: parent.document.form1.filename.value= "Aqing"
14.body problem
Firefox's body exists before the body tag is fully read by the browser, while IE's body must exist after the body tag is fully read by the browser.
For example:
Firefox:
Document.body.onclick=function (evt) {evtevt=evt | | window.event; alert (evt);} script > body > IE&Firefox: body > document.body.onclick=function (evt) {evtevt=evt | | window.event; alert (evt);} script > the above is what Xiaobian shared to explore the compatibility of IE and Firefox in JavaScript. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.