开发者

Looping div with jquery

I am just curious how to loop a div from my return json result.

This is my desired result:

开发者_开发知识库
<div id="imgdiv">
  --wanna loop this div and all the inner div and everything as well 
  <div id="rbox" style="display:none">
    Doa ini telah dihantar sebanyak <span class="counter"></span> kali.
    <br/>
    <br/>
    <br/>
    <span class="buttonshare"><a href="">Klik untuk pilih doa</a></span>
  </div>
</div>

And here is my current jQuery code:

$.ajax({type :'GET',
        url : 'getallimg.php',
        dataType : 'json',
        success : function(data){
          $.each(data, function(i,item){
            $("#loader").hide(500);
            $("<div class='imgdiv'><img src='imagedoa/"+item.imgname+".jpg' width='450' height='150' /></div></br>")
            .appendTo("#doaimgbox");
           });-->stuck up here 

Here is the desire code I'm looking it

<div id="doaimgbox"><!-- parent div -->

       <!-- looping portion -->
      <!-- I wanna loop this div based on length json return result let's say 3 -->

        <div class="imgdiv">

            <img src="imagedoa/d0.jpg" width="400" height="150" />
            <div id="rbox">
                Was sent <span class="counter"></span> times.
                <br/>
                <br/>
                <br/>
                <span class="buttonshare"><a href="">Click to select</a></span>
            </div>
        </div>
    <!-- looping portion -->
</div><!-- end parent div -->

Really need help with it.


U can add create a template let say name is myTmpl

var myTmpl="<div id="imgdiv">--wanna loop this div and all the inner div and everything as well 
            <div id="rbox" style="display:none">
                Doa ini telah dihantar sebanyak <span class="counter"></span> kali.
                <br/>
                <br/>
                <br/>
                <span class="buttonshare"><a href="">Klik untuk pilih doa</a></span>
            </div>
        </div>"

and u can use it in your div let's say u want to append this for each data that returned from your ajax call

$.each(data,function(){
    $(myTmpl).appendTo('body');
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜