简体   繁体   English

如何使用JQuery更改image_tag帮助程序的源代码?

[英]how do I change the source of image_tag helper using JQuery?

I am using Image_tag helper and the assets pipeline from rails, this way: 我使用Image_tag helper和rails中的assets管道,这样:

<%= image_tag "win_jorge_start_0.jpg", :id => "image0" %>

I am trying to change the source of the image_tag using JQuery like this: 我试图使用JQuery更改image_tag的源代码,如下所示:

$('#image0').attr( "src" , "win_jorge_complete_0.jpg" );

the src of the image is changed as expected: 图像的src按预期更改:

<img alt="Win jorge start 0" src="win_jorge_complete_0.jpg" id="image0">

but the source path is not completed as it is when using the Image_tag helper: 但是使用Image_tag帮助程序时源路径未完成:

<img alt="Win jorge start 0" src="/assets/win_jorge_start_0-51b6339e1e0a021aa878ee8b54cb957a.jpg" id="image0">

is there a way to do this? 有没有办法做到这一点?

In your JavaScript use: 在您的JavaScript中使用:

$('#image0').attr( "src" , "<%= image_path "win_jorge_start_0.jpg", :id => "image0" %>" );

also see: AssetUrlHelper#image_path 另见: AssetUrlHelper#image_path

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

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