During the development process, you need to use js to dynamically add radio to the page, and use the document. createelement () method to implement it.CodeAs follows:
Code
VaR _ Radio = Document. createelement ( " Input " );
_ Radio. Type = " Radio " ;
_ Radio. Name = " _ Radio " ;
Document. Body. appendchild (_ radio );
_ Radio = Document. createelement ( " Input " );
_ Radio. Type = " Radio " ;
_ Radio. Name = " _ Radio " ;
Document. Body. appendchild (_ radio );
The Raido generated on ie cannot be selected, but Firefox can be selected. Then I tried the following code:
Code
VaR _ Radio = Document. createelement ( " <Input type = 'Radio 'name = '_ Radio'> " );
Document. Body. appendchild (_ radio );
_ Radio = Document. createelement ( " <Input type = 'Radio 'name = '_ Radio'> " );
Document. Body. appendchild (_ radio );
The radio generated on IE can be selected, but it is invalid in Firefox. Therefore, different browsers need to use different methods to generate radio. This can be achieved by determining whether the document has the uniqueid attribute, because uniqueid is a unique attribute of IE, to solve this problem, you can use the following code to ensure browser compatibility:
Code
If (Document. uniqueid ){
// IE browser Branch
VaR _ Radio = Document. createelement ( " <Input type = 'Radio 'name = '_ Radio'> " );
Document. Body. appendchild (_ radio );
_ Radio = Document. createelement ( " <Input type = 'Radio 'name = '_ Radio'> " );
Document. Body. appendchild (_ radio );
} Else {
// Non-IE browser Branch
VaR _ Radio = Document. createelement ( " Input " );
_ Radio. Type = " Radio " ;
_ Radio. Name = " _ Radio " ;
Document. Body. appendchild (_ radio );
_ Radio = Document. createelement ( " Input " );
_ Radio. Type = " Radio " ;
_ Radio. Name = " _ Radio " ;
Document. Body. appendchild (_ radio );
}
In addition, radio and checkbox generated through document. createelement ("input") cannot be obtained through the document. getelementsbyname () method in IE browsing.
Abstract: http://hotpepper.javaeye.com/blog/236338