Twitter bootstrap popovers close when opening new

房东的猫 提交于 2019-12-10 14:32:37

问题


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?

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:

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

Thanks in advance for your help to a poor JS n00b!


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/16426726/twitter-bootstrap-popovers-close-when-opening-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!