Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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_Html_Twitter Bootstrap - Fatal编程技术网

Javascript 如何通过单击popover本身中的按钮来关闭引导popover

Javascript 如何通过单击popover本身中的按钮来关闭引导popover,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,不幸的是,当我点击表单html按钮(在弹出框内)时,我很难让引导弹出框(在我的页面上的特定位置打开)关闭。我知道也有类似的问题,相信我,我已经尝试了一些相关的解决方案,但没有效果 我有以下Javascript代码,用于在我的页面上的特定元素处打开引导弹出框: setTimeout(function(){$('#bob').popover({ title:"Reaction", html:true, content:html }).popover('show')}, 1

不幸的是,当我点击表单html按钮(在弹出框内)时,我很难让引导弹出框(在我的页面上的特定位置打开)关闭。我知道也有类似的问题,相信我,我已经尝试了一些相关的解决方案,但没有效果

我有以下Javascript代码,用于在我的页面上的特定元素处打开引导弹出框:

setTimeout(function(){$('#bob').popover({

    title:"Reaction",
    html:true,
    content:html

}).popover('show')}, 1000);

// If a popover is open then can execute the following Javascript. Need to detect also which step clicked on...
$('#bob').on('shown.bs.popover', function () {            

    var close =  document.getElementById("yes");

    // if close button is clicked...
    close.addEventListener("click", function(){

        event.preventDefault();

        console.log("close button clicked");          

        $('#bob').popover('hide'); 

    }):

});
popover中按钮的关联html如下所示:

<button id ="yes" data-toggle="clickover" class = "btn btn-small btn-primary pull-right">Yes</button>
不幸的是,上述方法不起作用

我还研究了该问题的其他答案/解决方案,并尝试了以下方法,但均无效:

<button id ="yes" data-toggle="clickover" class = "btn btn-small btn-primary pull-right" onclick="event.preventDefault(); $(&quot;id&quot;).popover(&quot;hide&quot;);">Yes</button>
如果有人能给我一些线索/提示,告诉我如何让这项工作顺利进行,我将不胜感激


善良的问候

代码本身有错误。您忘记在id选择器之前添加#

//如果popover打开,则可以执行以下Javascript。还需要检测单击了哪个步骤

$("#"+id).on('shown.bs.popover', function () {            

   var close =  document.getElementById("yes");

   // if close button is clicked...
   close.addEventListener("click", function(){

       event.preventDefault();

       console.log("close button clicked");          


       $("#"+id).popover('hide'); 

    }):

});
第一件事-错误:

  • 在中的第三行末尾有一个冒号而不是分号 最后,
  • 这里

    close.addEventListener("click", function(){
    
        event.preventDefault();
    
  • 您忘记将
    'event'
    放在函数args中

    主要问题是:您试图过早地分配事件处理程序
    'show.bs.popover'
    。把它放到
    文档中。ready
    应该可以解决这个问题

    setTimeout(function(){$('#bob').popover({
    
        title:"Reaction",
        html:true,
        content:html
    
    }).popover('show')}, 1000);
    
    $(function(){//<---ADD THIS
        // If a popover is open then can execute the following Javascript. Need to detect also which step clicked on...
        $('#bob').on('shown.bs.popover', function () {            
    
            var close =  document.getElementById("yes");
    
            // if close button is clicked...
            close.addEventListener("click", function(event){
    
                event.preventDefault();
    
                console.log("close button clicked");          
    
                $('#bob').popover('hide'); 
    
            });
    
        });
    });//<---ADD THIS
    
    setTimeout(函数(){$('#bob').popover({
    标题:“反应”,
    是的,
    内容:html
    }).popover('show')},1000);
    
    $(function(){//你怎么知道“id”变量包含什么?你假设它只是一个数字,但它可以是一个“#number”形式的字符串。好的,请看我上面的代码编辑。我将id更改为“#bob”,但仍然不起作用。我想知道你是否有任何进一步的建议?当然可以写“number”我是指“identifier”。使用数据库的时间太长:)