twitter-bootstrap 在页面加载时加载 Twitter Bootstrap Popover

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12749859/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 15:29:49  来源:igfitidea点击:

Load a Twitter Bootstrap Popover on Page load

javascriptjquerytwitter-bootstrap

提问by Charlie Davies

I have the following BootStrap popover:

我有以下 BootStrap 弹出窗口:

<a href='#' id='example' rel='popover' data-placement='left' data-content='Its so simple to create a tooltop for my website!' data-original-title='Twitter Bootstrap Popover'>HEY</a>

And I want to show it when the page loads, so I added

我想在页面加载时显示它,所以我添加了

$('#example').popover('show')

to a function as follows at the end of the document:

到文档末尾的函数如下:

<script>
$(function ()
{ $("#example").popover(show);
});
</script>

but nothing happened.

但什么也没发生。

On page load I get nothing. However when I run $('#example').popover('show')in the console I get the popover working. How can I make the popover be shown when the page has loaded?

在页面加载时我什么也得不到。但是,当我$('#example').popover('show')在控制台中运行时,弹出窗口可以正常工作。如何在页面加载时显示弹出框?

回答by user2658807

I found this way to be convenient:

我发现这种方式很方便:

You can trigger the 'show' and set options in one fell swoop:

您可以一举触发“显示”并设置选项:

$('#elementToPointAt').popover({
   'placement':'bottom',
   'content':'Look at me!'
}).popover('show');

回答by zemirco

You forgot the quotes for show. This works:

你忘记了 的引号show。这有效:

$(function () { 
  $("#example").popover('show');
});

Full example would be:

完整的例子是:

<!DOCTYPE html>
<html lang="en">
  <head>
    <link href="css/bootstrap.min.css" rel="stylesheet">
  </head>

  <body>
    <a href='#' id='example' rel='popover' data-placement='right' data-content='Its so simple to create a tooltop for my website!' data-original-title='Twitter Bootstrap Popover'>HEY</a>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/script.js"></script>
    <script>
      $(function() { 
        $("#example").popover('show');
      });
    </script>
  </body>
</html>

回答by Tom

Run it after window is loaded like so:

在窗口加载后运行它,如下所示:

$(window).load(function(){
  $("#example").popover('show');
});

回答by Deepika Patel

$("#example").popover({'placement':'bottom'}).popover('show');

回答by shivam khandelwal

$(document).ready(function(){

window.setTimeout("$('#example').popover('show')",1000);

}

It works for me. Try it out.

这个对我有用。试试看。

回答by dsd

Trigger the click event of that anchor tag using jQuery like

使用 jQuery 触发该锚标记的点击事件,例如

$('[id$='example' ]').trigger("click");