js动态创建HTML(radio、checkbox...)[摘抄]

  1. function create(parentId,eleType,eleName,eleId,eleValue){   
  2.         var board = document.getElementById(parentId);   
  3.         var e = createElement("input",eleName);   
  4.         e.type = eleType;   
  5.         e.id = eleId;   
  6.         e.value = elevalue;    
  7.         board.appendChild(e);   
  8.         //设置选中   
  9.         e.setAttribute("checked","checked");   
  10.         //添加文字   
  11.         board.appendChild(document.createTextNode("Item"));   
  12.    }   
  13.       
  14.    function createElement(type, name) {      
  15.        var element = null;      
  16.        try {      
  17.           // First try the IE way; if this fails then use the standard way      
  18.           element = document.createElement_x('<'+type+' name="'+name+'">');      
  19.        } catch (e) {      
  20.           // Probably failed because we’re not running on IE      
  21.        }      
  22.        if (!element) {      
  23.           element = document.createElement(type);      
  24.           element.name = name;      
  25.        }      
  26.        return element;      
  27.     }  
原文地址:https://www.cnblogs.com/chenjiang/p/2405732.html