简体   繁体   English

Bootstrap popover在html中输出时不起作用

[英]Bootstrap popover doesn't work when outputed in html

When bootstrap popover is outputed in html() it doesn't work. 引导弹出窗口html()输出时,它不起作用。 Only the title is shown. 仅显示标题。 Is there any fix to this? 有没有解决办法?

You can also see the fiddle 您还可以看到小提琴

 $( "button" ).click(function() { $("p").html('<a href="#" title="hello, this is title" data-toggle="popover" data-trigger="hover" data-content="Some content">Hover over me</a>'); }); $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container"> <p>Click the button to add popover</p> <button class="btn">button</button> </div> 

The popover should be initiated after the button is clicked. 单击按钮应启动弹出窗口。 The document ready will only load once when the page is loaded. 准备就绪的文档仅在页面加载后加载一次。

$("button").click(function() {
   $("p").html('<a href="#" title="Header" data-toggle="popover" data-trigger="hover" data-content="Some content">Hover over me</a>');
    $('[data-toggle="popover"]').popover();   
});

https://jsfiddle.net/fLcz90q3/ https://jsfiddle.net/fLcz90q3/

$('[data-toggle="popover"]').popover(); call this code after updating html in <p> tag. <p>标记中更新html后调用此代码。 you have to re-initiate after appending/over writing html. 您必须在添加/覆盖html之后重新启动。 You have to add above code inside click event. 您必须在click事件中添加以上代码。

Code inside $(document).ready() will only works for when page loads. $(document).ready()代码仅在页面加载时有效。 To achieve on dynamically created element, you have to initiate after creating/updating element. 要实现动态创建的元素,必须在创建/更新元素之后启动。

 $( "button" ).click(function() { $("p").html('<a href="#" title="hello, this is title" data-toggle="popover" data-trigger="hover" data-content="Some content">Hover over me</a>'); $('[data-toggle="popover"]').popover(); }); $(document).ready(function(){ $('[data-toggle="popover"]').popover(); }); 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="container"> <p>Click the button to add popover</p> <button class="btn">button</button> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM