Home >Web Front-end >JS Tutorial >Summary of 7 Differences and Compatibility Writing Methods of JavaScript under IE and Firefox Browsers_Javascript Tips
Summary of 7 Differences and Compatibility Writing Methods of JavaScript under IE and Firefox Browsers_Javascript Tips
WBOYOriginal
2016-05-16 18:24:49917browse
In this article, the author introduces 7 differences between JavaScript in IE and Firefox. 1. CSS “float” value The most basic syntax for accessing a given CSS value is: object.style.property, using camelCase notation to replace the value with a connector, for example, To access the background-color value of a
with the ID "header", we use the following syntax:
document.getElementById("header").style.backgroundColor= "#ccc"; But since the word "float" is a JavaScript reserved word, we cannot use object.style.float to access it. Here, we can do this in two browsers: Write this in IE:
document.getElementById("header").style.styleFloat = "left"; Write this in Firefox:
2. Inferred styles of elements JavaScript can use the object.style.property syntax to easily access and modify a CSS style externally, but its limitations are these The syntax can only retrieve already set inline styles or styles set directly by JavaScript. It cannot access an external style sheet. To access the "inferred" style of an element, we can use the following code: Write this in IE:
var myObject = document.getElementById("header"); var myStyle = myObject .currentStyle.backgroundColor; Write this in Firefox:
var myObject = document.getElementById("header"); var myComputedStyle = document.defaultView.getComputedStyle(myObject, null); var myStyle = myComputedStyle.backgroundColor; 3. Access the "class" of the element Like "float", "class" is a reserved word in JavaScript, and in these two browsers In the container we use the following syntax to access "class". Write like this in IE:
var myObject = document.getElementById("header"); var myAttribute = myObject.getAttribute("className"); Write like this in Firefox :
var myObject = document.getElementById("header"); var myAttribute = myObject.getAttribute("class"); This syntax would also apply using the setAttribute method.
4. Access the "for" in the As mentioned in point 3, we also need to use invisible syntax distinction to access the
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn