Js dynamic addition check box Checkbox

Source: Internet
Author: User


  1. Var checkBox = document. createElement ("input ");
  2. CheckBox. setAttribute ("type", "checkbox ");
  3. CheckBox. setAttribute ("id", '20140901 ');
However, the generated checkbox does not contain text after the end. If you need to add it, you need to use
  1. Document. createTextNode ('xxx ')
Method to generate a text node, which is placed behind the checkbox.

The following code generates a checkbox and a text node, puts them in a li object, and then adds the li object to the ul object:
  1. Var executerDiv = $ ("executerDiv ");
  2. ExecuterDiv. innerHTML = "";
  3. Var ul = document. createElement ("ul ");
  4. For (var I = 0; I <tableDatas. length; I ++ ){
  5. Var arr = tableDatas [I];
  6. // Add the check box
  7. Var checkBox = document. createElement ("input ");
  8. CheckBox. setAttribute ("type", "checkbox ");
  9. CheckBox. setAttribute ("id", arr [0]);
  10. CheckBox. setAttribute ("name", arr [1]);
  11. Var li = document. createElement ("li ");
  12. Li. appendChild (checkBox );
  13. Li. appendChild (document. createTextNode (arr [1]);
  14. Ul. appendChild (li );
  15. }
  16. ExecuterDiv. appendChild (ul );
  17. // By [url = http://www.jbxue.com] http://www.jbxue.com [/url]
In the above Code, put the checkbox in li and ul, which can achieve a good arrangement. The CSS style set by UL and li is as follows:
  1. # ExecuterDiv {
  2. }
  3. # ExecuterDiv ul {
  4. Margin: 0px;
  5. Padding: 0px;
  6. List-style-type: none;
  7. Vertical-align: middle;
  8. }
  9. # ExecuterDiv li {
  10. Float: left;
  11. Display: block;
  12. Width: 100px;
  13. Height: 20px;
  14. Line-height: 20px;
  15. Font-size: 14px;
  16. Font-weight: bold;
  17. Color: #666666;
  18. Text-decoration: none;
  19. Text-align: left;
  20. Background: # ffffff;
  21. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.