twitter-bootstrap Twitter Bootstrap 弹出窗口不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17499438/
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
Twitter Bootstrap Popovers not working
提问by dennismonsewicz
Here is my HTML:
这是我的 HTML:
<div id="disclaimer">After 30 Days you'll have the option to keep your account for per month -no contract required-or revert to a single page free account.*</div>
JavaScript:
JavaScript:
$('#disclaimer').popover({
trigger: 'hover',
html: true,
placement: 'right',
content: 'hello world'
});
When I hover over the element, nothing happens.. no JavaScript errors or anything, not sure whats wrong
当我将鼠标悬停在元素上时,没有任何反应......没有 JavaScript 错误或任何东西,不知道出了什么问题
回答by Jonathan
Using your exact code, all I had to do to get it to work was wrap it in a function call and put the script below the div tag. If you placed your jQuery in an onload function it would work just as well. Good luck.
使用您的确切代码,我所要做的就是将其包装在函数调用中并将脚本放在 div 标记下方。如果您将 jQuery 放在 onload 函数中,它也能正常工作。祝你好运。
Use this:
用这个:
<div id="disclaimer" >After 30 Days you'll have the option to keep your account for per month -no contract required-or revert to a single page free account.*</div>
<script>
$(function ()
{
$('#disclaimer').popover(
{
trigger: 'hover',
html: true,
placement: 'right',
content: 'hello world'
});
});
</script>
OR
或者
$(document).ready(function()
{
$('#disclaimer').popover(
{
trigger: 'hover',
html: true,
placement: 'right',
content: 'hello world'
});
});
回答by lizz
i had been looking for over a day as to why my popover wasn't working after getting autodisabled due to events happening on my page (a complicated app, something that gets enabled/disabled depending on the state of what is going on) and the key was to NOT have it the document ready but to have it out in a function because it gets enabled after document initialization on a button click.
我一直在寻找为什么我的弹出窗口在由于我的页面上发生的事件(一个复杂的应用程序,根据正在发生的事情的状态启用/禁用的东西)而被自动禁用后无法工作的原因关键是不要让它准备好文档,而是将它放在一个函数中,因为它会在单击按钮的文档初始化后启用。

