0

Twitterブートストラップからポップオーバーコンポーネントを実装しようとしています:

$('.popover-button').popover({
    html: true,
    placement: 'bottom',
    content: $(this).data('content-id')
});

<button class="popover-button" data-content-id="div1">Click 1</button>
<button class="popover-button" data-content-id="div2">Click 2</button>
<button class="popover-button" data-content-id="div3">Click 3</button>

<div class="div1">Hello 1</div>
<div class="div2">Hello 2</div>
<div class="div3">Hello 3</div>

しかし、それは機能していません。すべてのボタンを反復処理している場合、通常のように $(this) を使用できないようです。

では、これを行う方法は?

4

2 に答える 2

2

要素をループして、それぞれを呼び出す必要がありますpopover

$('.popover-button').each(function(){
    $(this).popover({
        html: true,
        placement: 'bottom',
        content: $(this).data('content-id')
    });
});

次に、各要素の情報をメソッドに渡すことができます。

于 2013-10-14T17:08:19.673 に答える