最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Tooltip set on a button displaying a modal dialog is reappearing after closing the dialog - Stack Overflow

programmeradmin3浏览0评论

The problem description is in the title - the tooltip reappears when I close the modal dialog.

<script type="text/javascript">
    $(function () {
        $('[data-tooltip="tooltip"]').tooltip();
    });
</script>

<button type="button" class="btn btn-default" data-toggle="modal" data-target="#divModal" data-tooltip="tooltip" title="Tooltip!">
    <span class="glyphicon glyphicon-globe"></span>
</button>

see it happening here : /

The problem description is in the title - the tooltip reappears when I close the modal dialog.

<script type="text/javascript">
    $(function () {
        $('[data-tooltip="tooltip"]').tooltip();
    });
</script>

<button type="button" class="btn btn-default" data-toggle="modal" data-target="#divModal" data-tooltip="tooltip" title="Tooltip!">
    <span class="glyphicon glyphicon-globe"></span>
</button>

see it happening here : http://jsfiddle/2gdrL6sf/

Share Improve this question edited Sep 5, 2014 at 5:45 Bruno asked Sep 5, 2014 at 5:30 BrunoBruno 4,6757 gold badges61 silver badges115 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

The problem is that the button is gaining focus when the modal is closed. To get around the tooltip showing again after the modal is closed you could restrict the tooltips trigger to a hover like so:

$(function () {
    $('[data-tooltip="tooltip"]').tooltip({
        trigger: 'hover'
    });
});

I forked your JSFiddle and have a working demo you can check out.

Hope that helps!

In the button click handler, add a blur call to remove focus.

$('#myButton').click(function() {
    $(this).blur();
    $('#myDialog').dialog('open');
});

Buttons need to have focus and display a tooltip when not clicked so that assistive technologies can be effective. Somebody that's unable to use a mouse might need to tab between buttons. Setting the tooltip to only trigger on hover removes that capability.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论