I encountered a small problem today. During DOM construction, IE cannot pass element. setAttribute ('name', _ variable); and element. name = _ variable; this form adds the name attribute to the element, whether it is IE6 or IE7. (IE8 is acceptable, but IE8rc1 is not acceptable)
Later, I checked MSDN and got the following information:
Copy codeThe Code is as follows:
Internet Explorer 8 and later can set the NAME attribute at run time on elements dynamically created with the createElement method. to create an element with a NAME attribute in earlier versions of Internet Explorer, include the attribute and its value when using the createElement method.
That is to say, we must create a name attribute element by using tags with attributes and values. In order to ensure the compatibility of various browsers, the code can be written as follows:
Copy codeThe Code is as follows:
Var element = null;
Try {
// IE6/IE7 build Mode
Element = document. createElement ('<input name = "radio-button"> ');
} Catch (e ){
// W3C build Method
Element = document. createElement ('input ');
Element. name = 'radio-click ';
}
// Define other attributes
Element. id = 'radio-1'
Element. type = 'Radio ';
I used to be a Java developer. In actual work, the amount of JavaScript code is not much. In some of my own small applications, it is often just a bit of a joke (subconscious) avoid problems, such as cross-origin AJAX and IE Memory leakage. however, after the conversion to UED, JavaScript and interactive applications will certainly become the focus of my future work. There are many opportunities for problems of different sizes (almost every day ), in the process of solving various problems, I felt pain and happy. based on the principle of not doing anything, but not having to worry about it, it is necessary to record it and back it up for yourself to share it with others.