防止bootstrap工具提示隐藏在点击它上面

 他们叫我红豆 发布于 2023-01-30 18:19

当我点击它时,我想阻止工具提示隐藏.除了我点击身体的任何地方它应该隐藏它.

工具提示甚至可以在标签上工作.

小提琴:

http://jsfiddle.net/C5GBU/41/

HTML:

jQuery的:

$('[data-toggle="popover"]').popover({trigger:"focus"});

$('body').on('click', function (e) {
    $('[data-toggle="popover"]').each(function () {
        //the 'is' for buttons that trigger popups
        //the 'has' for icons within a button that triggers a popup
        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });                
});

Trevor.. 8

我可以建议触发弹出窗口 manually

var close = true;
$('[data-toggle="popover"]').popover({trigger:"manual"});

$(document).on('mousedown', function (e) {
    if($(e.target).hasClass('popover-content'))
        close = false;
    else
        close = true; 
});

$('[data-toggle="popover"]').on("blur",function(){
    if(close)
        $(this).popover('hide');
    else 
       $(this).focus();
});

$('[data-toggle="popover"]').on("focus",function(){
   if(close)
       $(this).popover('show'); 
});

示例:小提琴

针对标签问题的更新修复:

.blur功能更改为以下内容:

$('[data-toggle="popover"]').on("blur",function(){
    if(close)
        $(this).popover('hide');
    else {
       $(this).focus();
       close = true;
    }
});

小提琴

1 个回答
  • 我可以建议触发弹出窗口 manually

    var close = true;
    $('[data-toggle="popover"]').popover({trigger:"manual"});
    
    $(document).on('mousedown', function (e) {
        if($(e.target).hasClass('popover-content'))
            close = false;
        else
            close = true; 
    });
    
    $('[data-toggle="popover"]').on("blur",function(){
        if(close)
            $(this).popover('hide');
        else 
           $(this).focus();
    });
    
    $('[data-toggle="popover"]').on("focus",function(){
       if(close)
           $(this).popover('show'); 
    });
    

    示例:小提琴

    针对标签问题的更新修复:

    .blur功能更改为以下内容:

    $('[data-toggle="popover"]').on("blur",function(){
        if(close)
            $(this).popover('hide');
        else {
           $(this).focus();
           close = true;
        }
    });
    

    小提琴

    2023-01-30 18:22 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有