twitter-bootstrap Bootstrap 弹出窗口不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12845876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap Popover not working
提问by Bruno Teixeira
I'm trying to implement the bootstrap popover on a website but for some reason it isn't working.
我正在尝试在网站上实现 bootstrap popover,但由于某种原因它不起作用。
The console does not output any errors and I've also made an alert just to check if the JS was working and it is.
控制台没有输出任何错误,我也发出了警报,只是为了检查 JS 是否正常工作。
My code is:
我的代码是:
Head:
头:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function () {
alert("Aaaa");
$('#example').tooltip();
});
</script>
HTML
HTML
<a href="#" rel="tooltip" data-placement="right"
data-original-title="Tooltip on right"
回答by Joe
For performance reasons, the Tooltip and Popover data-apis are opt in. If you would like to use them just specify a selector option.
出于性能原因,Tooltip 和 Popover data-apis 是可选的。如果您想使用它们,只需指定一个选择器选项。
-- Bootstrap 文档
But if you've covered that, it would seem you need to add an id attr to you a tag:
但是,如果您已经涵盖了这一点,似乎您需要向您添加一个 id attr 标签:
<a href="#" rel="tooltip" data-placement="right" data-original-title="Tooltip on right">Stuff</a>
回答by computer_smile
[EDIT] try the other answer first.
[编辑] 先尝试其他答案。
I think you need to have an id to select in your html to reference in your JS
我认为你需要有一个 id 在你的 html 中选择以在你的 JS 中引用
Also, try it without the type='text/javascript' in the body script.
此外,尝试在正文脚本中不使用 type='text/javascript' 。
From
从
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function () {
alert("Aaaa");
$('#example').tooltip();
});
</script>
to-
到-
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
alert("Aaaa");
$('#example').tooltip();
});
</script>
回答by xpto
This works for all elements at same time.
这同时适用于所有元素。
$("[rel='tooltip']").tooltip();

