var newdiv=document.createElement("div"); newdiv.className="switch-animate switch-on" newdiv.id="switch_div" document.getElementById("dhcpd_div").appendChild(newdiv); var rinput = document.createElement("input"); rinput.setAttribute("type","checkbox"); rinput.setAttribute("name","dhcpd_name"); rinput.setAttribute("id",'dhcpd'); document.getElementById('switch_div').appendChild(rinput); rinput.setAttribute("checked",'checked'); var spanON = document.createElement("span"); spanON.className = "switch-left switch-success"; spanON.innerHTML = "ON"; document.getElementById("switch_div").appendChild(spanON); var label_var = document.createElement("label"); label_var.innerHTML = " "; document.getElementById("switch_div").appendChild(label_var); var spanOFF = document.createElement("span"); spanOFF.className = "switch-right switch-warning"; spanOFF.innerHTML = "OFF"; document.getElementById("switch_div").appendChild(spanOFF);
上面是我整理给大家的如何在js中创建div,span,label,希望今后会对大家有帮助。
相关文章:
js中如何建立model数据模型(代码奉上,简单易懂)
原生JS实现判断碰撞的方法(趣味实例)
有关在JS 获取JSON数据简单调用(代码附上,简单粗暴)