動的リストで Twitter Bootstrap のポップオーバーを使用しています。リスト項目にはボタンがあり、ボタンをクリックするとポップオーバーが表示されます。非動的でテストしたところ、問題なく動作しました。
これは非動的リスト用の私の JavaScript です
$("button[rel=popover]").popover({
placement : 'right',
container : 'body',
html : true,
//content:" <div style='color:red'>This is your div content</div>"
content: function() {
return $('#popover-content').html();
}
})
.click(function(e) {
e.preventDefault();
});
ただし、動的リストではうまく機能しません。ボタンを「2回」クリックすると表示され、最初にクリックしたリスト項目の1つだけが表示されます。
私のhtml:
<ul id="project-list" class="nav nav-list">
<li class='project-name'>
<a >project name 1
<button class="pop-function" rel="popover" ></button>
</a>
</li>
<li class='project-name'>
<a>project name 2
<button class="pop-function" rel="popover" ></button>
</a>
</li>
</ul>
<div id="popover-content" style="display:none">
<button class="pop-sync"></button>
<button class="pop-delete"></button>
</div>
動的な私の JavaScript:
$(document).on("click", "#project-list li" , function(){
var username = $.cookie("username");
var projectName = $(this).text()
$("li.active").removeClass("active");
$(this).addClass("active");
console.log("username: " +username + " project name: "+projectName );
});
$(document).on("click", "button[rel=popover]", function(){
$(this).popover({
placement : 'right',
container : 'body',
html : true,
content: function() {
return $('#popover-content').html();
}
}).click(function(e){
e.preventDefault();
})
});
//for close other popover when one popover button click
$(document).on("click", "button[rel=popover]" , function(){
$("button[rel=popover]").not(this).popover('hide');
});
同様の問題を検索しましたが、問題を解決するものはまだ見つかりません。誰かアイデアがあれば教えてください。助けてくれてありがとう。