Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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 bootstrap3popover_Javascript_Jquery_Ruby On Rails_Twitter Bootstrap_Twitter Bootstrap 3 - Fatal编程技术网

Javascript bootstrap3popover

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

我有一个显示图像的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.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

});