Javascript bootstrap3popover
我有一个显示图像的popover: 我的html: 我的js:Javascript bootstrap3popover,javascript,jquery,ruby-on-rails,twitter-bootstrap,twitter-bootstrap-3,Javascript,Jquery,Ruby On Rails,Twitter Bootstrap,Twitter Bootstrap 3,我有一个显示图像的popover: 我的html: 我的js: $('#btn2').popover trigger: "hover", html: true 我想将此片段导出到我的js: “数据内容”=>“{image\u标记CarConfiguration.last.image\u url.to\u s}” 如何操作?您可以在定义popover的js函数中设置内容 应该是这样的: var myPopoverContent = "#{ image_tag CarConfiguration.l
$('#btn2').popover trigger: "hover", html: true
我想将此片段导出到我的js:
“数据内容”=>“{image\u标记CarConfiguration.last.image\u url.to\u s}”
如何操作?您可以在定义popover的js函数中设置内容 应该是这样的:
var myPopoverContent = "#{ image_tag CarConfiguration.last.image_url.to_s}".html_safe;
$('#btn2').popover({
trigger: 'hover',
html: true,
content: myPopoverContent
});
谢谢您的帮助。但是这段代码不能正常工作。问题在于:var mypopcovercontent=“#{image_-tag-CarConfiguration.last.image_-url.to_-s}”.html_-safe;它无法加载此照片。我不知道如何评估javascript中的ruby代码。我不熟悉RubyonRails,但如果您可以将其作为数据内容标记返回,那么您可以添加一个隐藏输入并将值设置为url。这样:%a#hiddenInput{“value”=>“#{image_tag CarConfiguration.last.image_url.to_s}.html_safe}然后您可以在js代码中检索值,如下所示:var myPopoverContent=$(“#hiddenInput”).val()
var myPopoverContent = "#{ image_tag CarConfiguration.last.image_url.to_s}".html_safe;
$('#btn2').popover({
trigger: 'hover',
html: true,
content: myPopoverContent
});