How JavaScript dynamically adds a checkbox check box:
In real-world applications, you might need to add a dynamic check box, and here's a quick introduction to how to do this.
Simply creating a check box is easy and the code is as follows:
var ocheckbox=document.createelement ("input"); Ocheckbox.setattribute ("type", "checkbox"); o Checkbox.setattribute ("id", "Mayi");
But this is just a CheckBox object created, but often not enough to meet the actual needs, because in the actual application, usually in the checkbox before or after the check box is descriptive text, the following describes how to achieve this effect:
The method is to create a CheckBox object and then create a text node and add it to the Div.
The code is as follows:
<!DOCTYPE HTML> <HTML> <Head> <MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Add checkbox check box-Ant tribe</title><Scripttype= "Text/javascript"> varoCheckBox=Document.createelement ("input");varMyText=document.createTextNode ("Ant Tribe"); Ocheckbox.setattribute ("type","checkbox"); Ocheckbox.setattribute ("ID","Mayi"); Window.onload=function(){ varmydiv=document.getElementById ("mydiv"); Mydiv.appendchild (oCheckBox); Mydiv.appendchild (MyText);}</Script> </Head><Body><DivID= "Mydiv"></Div></Body></HTML>
The code above dynamically creates a CheckBox object followed by text .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8200
For more information, refer to: http://www.softwhy.com/javascript/
How JavaScript dynamically adds checkbox check box