2013-07-16 117 views
0

我在自舉popover中放置了一些自定義html。現在我要綁定使用JavaScript這些輸入,但我不能這樣做...Bootstrap popover問題

所以,這裏是一個簡單的例子可以解釋清楚我的問題: http://jsfiddle.net/53pD6/16/

<button class="btn btn-small btn-popover" type="button" data-original-title="Popover" data-placement="bottom">*</button> 

<!-- Popover html boby (Display attribute is none!) --> 
<div id="popover_content_wrapper" style="display: none"> 
    <input type="checkbox" class="chbox"/>Click me (no effect) 
</div> 

<input type="checkbox" class="chbox"/>Click me (here it's Ok) 

和JS :

$(function(){ 
    $('.btn-popover').popover({ 
     html : true, 
     content: function() { 
      return $('#popover_content_wrapper').html(); 
     } 
    }); 

    $(".chbox").change(function(){ 
     alert(1); 
    }); 
}); 

我只想在彈出窗口中將複選框綁定到函數中。我該怎麼做?

回答

1

由於.popover()不提供一種方法來附加事件處理程序,我知道解決這個唯一的方法是:

$('body').on('click', '.chbox', function() { 
    alert(1); 
}); 

更新小提琴:http://jsfiddle.net/53pD6/17/

+0

是的,它的作品!謝謝! –