Create divs from Array elements

前端 未结 4 773
孤独总比滥情好
孤独总比滥情好 2020-12-05 15:43

I have different strings in my array. Is it possible to create a divs like

for each array element in my HTML page?

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 16:08

    A Basic For Loop + jQuery should do it. Just replace body with a selector for the container you want to add the divs to. Here is a fiddle showing the technique in use.

    var myCars=new Array("Saab","Volvo","BMW");
    
    for(var x=0; x' + myCars[x] + '
    '); }

提交回复
热议问题