"Float" attribute of css
[Analysis description] the most basic syntax for accessing a given css value through special webpage effects is: object. style. property, but some css attributes have the same name as the reserved words in the special effect on a webpage, such as "float", "for", and "class". Different browsers use different methods.
Write in ie as follows:
Document. getelementbyid ("header"). style. stylefloat = "left ";
Write in firefox as follows:
Document. getelementbyid ("header" ).style.css float = "left ";
[Compatible processing] add a judgment before writing to determine whether the browser is ie:
If (document. all) {document. getelementbyid ("header "). style. stylefloat = "left";} else {document. getelementbyid ("header" ).style.css float = "left ";}
2. Access "for" in the <label> label"
[Analysis description] similar to the "float" attribute, you also need to access "for" in the <label> label using non-existent Syntax differentiation ".
Write in ie as follows:
Var myobject = document. getelementbyid ("mylabel"); var myattribute = myobject. getattribute ("htmlfor ");
Write in firefox as follows:
Var myobject = document. getelementbyid ("mylabel"); var myattribute = myobject. getattribute ("");
[Compatible processing] The solution is to determine the browser type first.
3. Access and set class attributes
[Analysis description] because the class is reserved for javascript, the two browsers use different javascript methods to obtain this attribute.
For all ie versions earlier than ie8.0:
Var myobject = document. getelementbyid ("header"); var myattribute = myobject. getattribute ("classname ");
For ie8.0 and firefox:
Var myobject = document. getelementbyid ("header"); var myattribute = myobject. getattribute ("class ");
In addition, when setattribute () is used to set the class attribute, the two browsers also have the same difference.
Setattribute ("classname", value );
This method applies to all ie versions earlier than ie8.0. Note: ie8.0 does not support the "classname" attribute.
Setattribute ("class", value); applicable to ie8.0 and firefox.
[Compatible processing]
Method 1 and both are written as follows:
Var myobject = document. getelementbyid ("header"); myobject. setattribute ("class", "classvalue"); myobject. setattribute ("classname", "classvalue"); // set the class of the header to classvalue
Method 2: both ie and ff support object. classname, so you can write as follows:
Var myobject = document. getelementbyid ("header"); myobject. classname = "classvalue"; // set the class of the header to classvalue
Method 3: first determine the browser type, and then use the corresponding method based on the browser type.
4. Assignment of object width and height
[Analysis description] The statement similar to obj. style. height = imgobj. height in firefox is invalid.
[Compatible processing] use obj. style. height = imgobj. height + 'px ';
>