循环创建多个元素
1.JQuery
function loopEvent(loopClass,n,ele){
var text = "";
for (var i = 0; i <=n; i++) {
text += $(loopClass).append("<"+ele+">"+i+"</"+ele+">");
}
}
loopEvent($(".starTime"),23,"li");
loopEvent($(".loop"),60,"option");
2.Js
function loopEle(targetEle,num,ele){
var text = '';
for(var i=0; i<num; i++){
text += '<'+ele+'>' + i +'<'+ele+'>';
}
return text;
}
document.getElementById(targetEle).appendChild(loopEle(20,'li'))