This example introduces how to dynamically add checkbox checkbox in JavaScript:
In actual applications, you may need to add check boxes dynamically. Here is a brief introduction to how to achieve this effect.
It is easy to simply create a checkbox, the code is as follows:
var oCheckbox=("input"); ("type","checkbox"); ("id","mayi");
However, this is just creating a checkbox object, but it often cannot meet the actual needs, because in actual applications, there are generally explanatory texts in front of or after the checkbox checkbox. Here is a description of how to achieve this effect:
The method is to create a checkbox object, then create a text node, and then add it to the div.
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <title>Add tocheckboxCheck box</title> <script type="text/javascript"> var oCheckbox=("input"); var myText=("Ant Tribe"); ("type","checkbox"); ("id","mayi"); =function(){ var mydiv=("mydiv"); (oCheckbox); (myText); } </script> </head> <body> <div ></div> </body> </html>
The above code dynamically creates a checkbox object, followed by text, I hope it will be helpful for everyone's learning JavaScript.