2014-12-02 115 views
0

我有這個引導程序輪播腳本,但觸發器是一個附加按鈕。我是js的大三學生,我不確定我應該怎麼做,或者讓他們工作並更改代碼。你能幫我解決這個問題嗎?也可能告訴我應該如何使用它。日Thnx提前讓jquery處理動態內容

<script> 
     /* activate the carousel */ 
    $("#modal-carousel").carousel({interval:false}); 

    /* change modal title when slide changes */ 
    $("#modal-carousel").on("slid.bs.carousel", function() { 
     $(".modal-title").html($(this).find(".active img").attr("title")); 
    }) 

    /* when clicking a thumbnail */ 
    $(".galz .gal").click(function(){ 
     var content = $(".carousel-inner"); 
     var title = $(".modal-title"); 

     content.empty(); 
     title.empty(); 

     var id = this.id; 
     var repo = $("#img-repo .item"); 
     var repoCopy = repo.filter("#" + id).clone(); 
     var active = repoCopy.first(); 

     active.addClass("active"); 
     title.html(active.find("img").attr("title")); 
     content.append(repoCopy); 

     // show the modal 
     $("#modal-gallery").modal("show"); 
    }); 

</script> 

回答

2

使用事件代表團

$(document).on('click', 'element', function() { 
    // Your function code 
}); 
+0

日Thnx傢伙,它的工作,現在我知道如何使用「的」由我自己:P – user3058067 2014-12-02 11:22:02

2

您可以撥打單擊此方式也

$(document).delegate('.galz', 'click', function() { 
     //your code 

    });