Jquery append() limit

前端 未结 2 1249
醉话见心
醉话见心 2021-01-17 09:13

Hi all I have this scripts and I want to append happen only six times

$(\".upload_add\").click(function(){
    $(\"#film_upload_side\")
    .ap         


        
相关标签:
2条回答
  • 2021-01-17 09:49

    Set a counter:

    var counter = 0;
    $(".upload_add").click(function(){
        counter++;
        if(counter<7)
        $("#film_upload_side").append('<div class="photo_upload_button"> Shoose file to upload</div>');
    
    });
    
    0 讨论(0)
  • 2021-01-17 09:53
    var flag = 0;
    $(".upload_add").click(function(){
        flag++;
        if(flag<=6)
        $("#film_upload_side").append('<div class="photo_upload_button"> Shoose file to upload</div>');
    
    });
    

    check flag when it becomes 6, then stop appending.

    0 讨论(0)
提交回复
热议问题