我试图将 bootstrap popover 内容与 html 属性分开,就像对其他组件所做的那样,但我无法让它工作......
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Popover Example</h3>
<p>Popovers are not CSS-only plugins, and must therefore be initialized with jQuery: select the specified element and call the popover() method.</p>
<div class="popover" >
<a href="#" class="popover-toggle" title="Popover Header" >Toggle popover</a>
<div class="popover-content">
Here I am
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>
您有简单的锚点和一些不应显示的 div。
<a href="#" id="tglr" class="popover-toggle" title="Popover Header">Toggle popover</a>
<div id="customdiv" style="display: none">
Here <b>I</b> am
</div>
在 JS 中,我们获取锚点(通过 id)并在其上安装 popover,有 2 个选项:第一个“html” - 允许显示 html 而不是简单文本,第二个指定从 div 获取的内容:
$(document).ready(function(){
$('#tglr').popover({
html : true,
content: function() {
return $('#customdiv').html();
}
});
});
这是你的例子https://jsfiddle.net/DTcHh/8529/ https://jsfiddle.net/DTcHh/8529/
您的代码问题之一 - 您执行 $('[data-toggle="popover"]') ,它将选择 data-toggle 等于“popover”的标签),但您没有这样的标签。如果你想以这种方式初始化弹出窗口,你应该像这样声明锚点:
<a href="#" data-toggle="popover" class="popover-toggle" title="Popover Header">Toggle popover</a>
但在您的情况下,您只有一个链接和一个自定义弹出窗口,因此更合乎逻辑的是通过 id 选择它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)