Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Bootstrap popover会破坏内容_Javascript_Twitter Bootstrap_Popover - Fatal编程技术网

Javascript Bootstrap popover会破坏内容

Javascript Bootstrap popover会破坏内容,javascript,twitter-bootstrap,popover,Javascript,Twitter Bootstrap,Popover,我有一个Rails应用程序,包含以下HTML和咖啡脚本: <span id="CEO_portrait"><%= image_tag "CEO_portrait.png", class: "portrait" %></span> <div id="tooltip_container"> <div id="CEO_biography"> "The CEO founded the company in 1969." <

我有一个Rails应用程序,包含以下HTML和咖啡脚本:

<span id="CEO_portrait"><%= image_tag "CEO_portrait.png", class: "portrait" %></span>
<div id="tooltip_container">
  <div id="CEO_biography">
    "The CEO founded the company in 1969."
  </div>
</div>

$ ->
  $('#CEO_portrait').popover
    title: "James E. Lee"
    placement: "top"
    trigger: "hover"
    html: true
    container: "#tooltip_container"
    content: ->
      $('#CEO_biography')

“首席执行官于1969年创立了这家公司。”
$ ->
$(“#CEO_肖像”).popover
标题:“詹姆斯·E·李”
位置:“顶部”
触发器:“悬停”
html:对
容器:“#工具提示_容器”
内容:->
$(《首席执行官传记》)
当我的鼠标第一次悬停在“#CEO_肖像”span上时,弹出窗口显示相应的内容。但是,当我的鼠标离开span时,id为“CEO_传记”的div“已删除。因此,当我再次将鼠标悬停在“CEO肖像”上时,标题会显示,但内容不会显示。我不明白为什么会这样。如何使内容持久化?

测试
“首席执行官于1969年创立了这家公司。”
在bootstrap 3和bootstrap 2.3.2中,它适用于我

是的,内容会消失,但下次我悬停时,内容仍在popover上。看看这个例子


确保已加载所有引导脚本/css等。

将内容保存在事件之外:

$ ->
 myContent = $('#CEO_biography') // save the content for future use

 $('#CEO_portrait').popover
 title: "James E. Lee"
 placement: "top"
 trigger: "hover"
 html: true
 // container: "#tooltip_container" // I don't know why you use this
 content: ->
   myContent
以下是我使用数据属性的工作解决方案:

$("[data-toggle='popover-div']").each ->
 that = $(this)
 content = $(that.data("content-div")) // Save content of the id given in "data-content-div"

 that.popover
   html: true
   content: ->
     content
玉石

a.btn.btn共享(数据切换=“popover div”,数据内容div=“#共享popover”,
数据触发器=“单击”,数据放置=“顶部”)
|分享
.share popover包装器//显示:无
#共享爆米花
//[…内容放在这里…]

@user1380016如果回答了您的问题,请将此答案标记为已接受,否则请就未解决的问题提供反馈。谢谢
$("[data-toggle='popover-div']").each ->
 that = $(this)
 content = $(that.data("content-div")) // Save content of the id given in "data-content-div"

 that.popover
   html: true
   content: ->
     content
a.btn.btn-share(data-toggle="popover-div", data-content-div="#share-popover",
data-trigger="click", data-placement="top")
  | Share <i class="fa fa-share"></i>

.share-popover-wrapper // Display: none
  #share-popover
   // [... Content goes here ...]