Javascript 如何创建引导Popover关闭选项
正如您在中所看到的,我使用了中的答案使引导弹出框在外部单击时消失。现在,我想在右上角添加一个“x”,点击后关闭弹出窗口 有没有一种简单的方法可以在popover的右上角创建一个可点击的“x”,当点击时它会关闭popover HTML:Javascript 如何创建引导Popover关闭选项,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,正如您在中所看到的,我使用了中的答案使引导弹出框在外部单击时消失。现在,我想在右上角添加一个“x”,点击后关闭弹出窗口 有没有一种简单的方法可以在popover的右上角创建一个可点击的“x”,当点击时它会关闭popover HTML: <h3>Live demo</h3> <div class="bs-docs-example" style="padding-bottom: 24px;"> <a href="#" class="btn btn-l
<h3>Live demo</h3>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="btn btn-large btn-danger" data-toggle="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
以下是jquery代码: 这一个只是在右上角添加了X按钮:
var isVisible = false;
var clickedAway = false;
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
$('.popover-title').append('<button type="button" class="close">×</button>');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function(e) {
if(isVisible & clickedAway)
{
$('.btn-danger').popover('hide')
isVisible = clickedAway = false
}
else
{
clickedAway = true
}
});
var isVisible=false;
var clickedAway=false;
$('.btn-danger').popover({
是的,
触发器:“手动”
})。单击(功能(e){
$(this.popover('show');
$('.popover title')。追加('×;');
ClickedWay=false
isVisible=true
e、 预防默认值()
});
$(文档)。单击(函数(e){
如果(可见并单击路径)
{
$('.btn danger').popover('hide'))
isVisible=ClickedWay=false
}
其他的
{
ClickedWay=true
}
});
此按钮仅在单击X按钮时关闭弹出窗口:
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
$('.popover-title').append('<button type="button" class="close">×</button>');
$('.close').click(function(e){
$('.btn-danger').popover('hide');
});
e.preventDefault();
});
$('.btn-danger').popover({
是的,
触发器:“手动”
})。单击(功能(e){
$(this.popover('show');
$('.popover title')。追加('×;');
$('.close')。单击(函数(e){
$('.btn danger').popover('hide');
});
e、 预防默认值();
});
我知道这个问题已经得到了回答,但是你的帖子帮助了我。偶然发现了一种更简单的方法来完成这项任务,假设您的类“.pop”中有所有的弹出窗口,这应该可以解决您的所有问题
$('.pop').on({
click:function(){
$('.pop').not(this).popover('hide');
}
});
谢谢你!我成功了!唯一的问题是,当我将其添加到我的站点时,单击“x”关闭弹出窗口,出于某种原因,也会提交我的表单。你知道为什么吗?既然你从技术上回答了我的问题,我也要给你一张支票!仍在处理表单提交问题。您好,问题不在此代码中。我相信这是在其他地方,除非你把这个按钮变成了提交按钮…解决了,这是因为“我得到了它,但不是一个按钮,而是一个链接”。请尝试以下操作:×;。可能会像“sumbit”按钮一样识别它,所以如果您指定type=“button”,可能会解决您的问题。@JorgeCode的代码可以工作。我使用第一个,但没有在标题行中添加关闭按钮。(由于缺乏特权,无法对豪尔赫准则答案发表评论)
$('.pop').on({
click:function(){
$('.pop').not(this).popover('hide');
}
});