Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击Popover触发器元素时,如何关闭/关闭引导Popover?_Javascript_Jquery_Twitter Bootstrap_Onclick_Popover - Fatal编程技术网

Javascript 单击Popover触发器元素时,如何关闭/关闭引导Popover?

Javascript 单击Popover触发器元素时,如何关闭/关闭引导Popover?,javascript,jquery,twitter-bootstrap,onclick,popover,Javascript,Jquery,Twitter Bootstrap,Onclick,Popover,jsFiddle: 屏幕截图: <button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button> <div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes insid

jsFiddle:

屏幕截图:

<button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
<div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
$('#popoverId').popover({
    html: true,
    title: 'Popover Title<a class="close" href="#");">&times;</a>',
    content: $('#popoverContent').html(),
});

$('#popoverId').click(function (e) {
    e.stopPropagation();
});

$(document).click(function (e) {
    if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
        $('#popoverId').popover('hide');
    }
});

以下是有效的方法:

  • 单击按钮打开弹出窗口
  • 在弹出窗口外单击关闭弹出窗口
  • 单击
    关闭弹出窗口。关闭
    按钮
  • 但是。。。当您再次单击原始按钮时,我无法关闭popover。相反,popover会时断时续地闪烁

    自己复制。

    我怎样才能做到这一点

    HTML:

    <button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
    <div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
    
    $('#popoverId').popover({
        html: true,
        title: 'Popover Title<a class="close" href="#");">&times;</a>',
        content: $('#popoverContent').html(),
    });
    
    $('#popoverId').click(function (e) {
        e.stopPropagation();
    });
    
    $(document).click(function (e) {
        if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
            $('#popoverId').popover('hide');
        }
    });
    
    单击以切换弹出窗口
    这个丰富的html内容放在popover中
    
    JS:

    <button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
    <div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
    
    $('#popoverId').popover({
        html: true,
        title: 'Popover Title<a class="close" href="#");">&times;</a>',
        content: $('#popoverContent').html(),
    });
    
    $('#popoverId').click(function (e) {
        e.stopPropagation();
    });
    
    $(document).click(function (e) {
        if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
            $('#popoverId').popover('hide');
        }
    });
    
    $('popoverId').popover({
    是的,
    标题:“Popover标题”,
    内容:功能(){
    返回$('popcovercontent').html();
    }
    });
    var isVisible=false;
    var clickedAway=false;
    $('.popoverThis').popover({
    是的,
    触发器:“手动”
    })。单击(功能(e){
    $(this.popover('show');
    $('.popover content')。追加('×;');
    ClickedWay=false
    isVisible=true
    e、 预防默认值()
    });
    $(文档)。单击(函数(e){
    如果(可见并单击路径){
    $('.popoverThis').popover('hide'))
    isVisible=ClickedWay=false
    }否则{
    ClickedWay=true
    }
    });
    
    你想这样工作吗

    $('popoverId').popover({
    是的,
    标题:“Popover标题”,
    内容:$('#popoverContent').html(),
    });
    $(“#popoverId”)。单击(函数(e){
    e、 停止传播();
    });
    $(文档)。单击(函数(e){
    if($('.popover').has(e.target).length==0)| |$(e.target).is('.close')){
    $('popoverId')。popover('hide');
    }
    });
    
    我用这个:

    <div id='content'>something here</div>
     $('[data-toggle=popover]').popover({
            html: true,
            content: function () {
                return $('#content').html();
            }
        }).click(function (e) {
            $('[data-toggle=popover]').not(this).popover('hide');
        });
    

    只需使用此代码即可完成

    这里有些东西
    $('[data toggle=popover]')。popover({
    是的,
    内容:功能(){
    返回$('#content').html();
    }
    })。单击(功能(e){
    $('[data toggle=popover]')。而不是(this.popover('hide');
    });
    
    此简单代码将隐藏页面上的所有弹出窗口
    $('.popover').popover('hide')

    不,我不能让popover在任何地方点击就消失。popover应该只在(1)关闭、(2)在.popover外,(3)在原始按钮上关闭。你应该可以随意点击popover,而不必关闭它。就像这样:除非再次点击红色按钮,否则会关闭popover。很好。这很有效。。。除此之外,现在我每页只能有一个popover(除非我为每个popover添加stopPropagation)。为什么它不能只在类中工作?不管怎样,它可以完美地在多个按钮中工作。请参阅更新的JSFIDLE以了解如何将某些ID更改为类:@Ryan class.popover在哪里?我不懂这个密码