For front-end users, they always need to deal with compatibility, CSS compatibility, and JS compatibility. Here I summarize the compatibility of getattribute () and setattribute () in different browsers and how to solve these problems:
1 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 2 < Html Xmlns = "Http://www.w3.org/1999/xhtml" > 3 < Head > 4 < Title > Kingwell </ Title > 5 < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" /> 6 < Body > 7 8 < Div ID = "Idheader" Class = "Class-header" Title = "Kingwell" Status = "1" > </ Div > 9 < Label ID = "Forusername" For = "Username" Title = "Kingwell" Status = "1" > </ Label > 10 11 </ Body > 12 </ Html >
1 VaR El = Document. getelementbyid ("idheader" ); 2 Alert (El. getattribute ("ID" )); 3 Alert (El. ID ); 4 IE firfox-> Idheader 5 6 Alert (El. getattribute ("class" )); 7 // IE6, IE7-> null IE8, ie9, Firefox-> class-Header 8 9 Alert (El. Class ); 10 // IE6, IE7, IE8-> error ie9, Firefox-> undefined 11 Alert (El. getattribute ("classname" )); 12 // IE6, IE7-> class-header; IE8, ie9, Firefox-> undefined 13 14 Alert (El. classname ); 15 // All-> class-Header 16 17 18 VaR Elfor = Document. getelementbyid ("forusername" ); 19 Alert (elfor. getattribute ("" )); 20 // IE6, IE7-> undefined IE8, 9, Firefox-> forusename 21 22 Alert (elfor. For ) 23 // IE6 or IE7 reports an error. The other values are undefined. 24 Alert (elfor. Title) 25 // Output all kingwell 26 Alert (elfor. status ); 27 // IE6-8-> 1 ie9, Firefox-> undefined 28 29 Alert (elfor. getattribute ("status" )) 30 // Output all 1
/* Summary:
1: We recommend that you use node. xxxx for general attributes.
2: We recommend that you use node. getattribute ("XXXX") for custom attributes ").
3: We recommend that you use node. getattribute ("XXX"), such as for in label, when the target is a keyword in Js.
4: Use classname instead of reserved words, such as class.
*/
Getattribute () and setattribute () are analyzed here.