这是 erb
<%= image_tag('number-of-people/slide1.png', class: 'def-img-width nop-style1', alt: 'style1') %>
这是 JS
if(chooseframe == 1){
$('.nop-style1').attr('src', "<%= image_path('number-of-people/style1-a3.png') %>");
}else if(chooseframe ==2){
$('.nop-style1').attr('src', "<%= image_path('number-of-people/style1-a4.png') %>");
}else if(chooseframe ==3){
$('.nop-style1').attr('src', "<%= image_path('number-of-people/style1-a5.png') %>" );
}
这是错误消息
错误的请求
错误的 URI `/order_details/%3C%=%20image_path('number-of-people/style1-a3.png')%20%%3E'。 WEBrick/1.3.1 (Ruby/2.2.3/2015-08-18) 门数:3000
这是 DOM 元素
<img class="def-img-width nop-style1" alt="style1" src="<%= image_path('number-of-people/style1-a5.png') %>" style="display: inline; -webkit-user-select: text;">
这意味着 image_path 没有执行!
最佳答案
代码没有问题,但问题是我在 .js 文件中有上述 JS 代码。对于 image_path ,它恰好使用 erb 语法。所以我将文件从 .js 更改为 .js.erb
关于javascript - 使用 JS 更改图像路径的错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35552267/