Twitter bootstrap popover在打开new时关闭

问题描述:

我不是JavaScript向导,所以我很遗憾这里显而易见的东西。我有一个使用 Twitter Bootstrap的弹出行为的多个链接的表 。我有它点击一个链接打开弹出窗口,然后点击另一个关闭第一个,但它几次尝试后变得有毛病,甚至开始关闭自己。所以问题是:一旦打开另一个弹出窗口,你如何正确地关闭弹出窗口?

I'm not JavaScript wizard, so I'm missing something obvious here I'm sure. I have a table that has multiple links utilizing Twitter Bootstrap's pop-over behavior. I have it where clicking on a link opens the pop-over, and clicking another closes the first, but it becomes glitchy after a few tries, and even starts to close itself. So the question is: How do you properly make pop-overs close once another is opened?

我在这里建立了一个JSFiddle(虽然它似乎根本没有工作): http://jsfiddle.net/ZnJ6b/

I set up a JSFiddle here (although it doesn't seem to be working at all): http://jsfiddle.net/ZnJ6b/

HTML:

<table>
    <thead>
        <th>Description</th>
        <th>Button</th>
    </thead>
    <tbody>
        <tr>
            <td>Item #1</td>
            <td><a href="#" class="btn show-text" data-toggle="popover" data-placement="right" data-content="Content for item one." title="" data-original-title="Review text">Click for text</a>

            </td>
        </tr>
        <tr>
            <td>Item #2</td>
            <td><a href="#" class="btn show-text" data-toggle="popover" data-placement="right" data-content="Content for item two." title="" data-original-title="Review text">Click for text</a>

            </td>
        </tr>
    </tbody>
</table>

Javascript:

Javascript:

$(this).popover('show');
$('.show-text').click(function () {
    $('.show-text').popover('hide');
});

提前感谢您对可怜的JS n00b的帮助!

试试这个:

$('.show-text').popover();
$('.show-text').click(function () {
     $('.show-text').not(this).popover('hide');
});