5

我需要使用 Twitter Bootstrap 3.0 制作一个弹出框显示 iframe,它 popopver 应该根据使用 href 的 onmouseover 事件的链接中提供的值显示 iframe。

我得到了第一个链接,但不是在 3.0 中,而是在 2.0.2 中,但第二个链接应该更改变量的值并显示不同的 iframe,我似乎不知道该怎么做。

$(window).load(function(){
var img = '<iframe frameborder="0" scrolling="no" height="220" width="420"
                  src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>';
$("#blob").popover({title: 'Last 10 spots for the selected station', content: img});
})  

<a href="#" id="blob" class="btn large primary" rel="popover" style="margin-top:
100px">hover for popover</a>

<a href="#" id="blob" class="btn large primary" rel="popover" onmouseover=""var img =
'<iframe frameborder="0" scrolling="no" height="220" width="420"
src="http://google.com"></iframe>';"" style="margin-top: 100px">hover for popover</a>
4

1 回答 1

8

You are overcomplicating i believe.

  • #1 You have duplicate id, you should assign unique id
  • You have syntax errors. See the console.
  • If you need to show bs popover on hover you just need to set the target in the bs popover settings or as a data-attribute.
  • You need to show the iframe as context and not the html text rep of iframe so you need to set data-trigger = "hover" or in the settings.
  • You need to inialte the popover or convert the object to popover by calling the constructor and the reason is stated in the document as below:

For performance reasons, the Tooltip and Popover data-apis are opt in. If you would like to use them just specify a selector option.

HTML:

<a href="#" id="blob" class="btn large primary" rel="popover" style="margin-top:
100px">hover for popover</a>

<a href="#" id="blob2" class="btn large primary" data-trigger="hover"  rel="popover" data-html="true" data-content='<iframe frameborder="0" scrolling="no" height="220" width="420"
src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>' style="margin-top: 100px">hover for popover</a>

JS:

$(window).load(function(){
var img = '<iframe frameborder="0" scrolling="no" height="220" width="420" src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>';
    $("#blob").popover({title: 'Last 10 spots for the selected station', content: img, html:true});
    $('[rel="popover"]').popover();
})  
于 2013-10-15T00:25:17.083 回答