javascript - 使用 JS 更改图像路径的错误请求

标签 javascript ruby-on-rails

这是 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="&lt;%= image_path('number-of-people/style1-a5.png') %&gt;" 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/

相关文章:

javascript - 选取文件上的纯 Javascript 事件监听器

ruby-on-rails - 如何定义包含反斜杠 ("\") 字符的 ruby​​ 数组?

ruby-on-rails - 我怎样才能在一个 block 中产生多个部分?

ruby-on-rails - 如何连接两个事件记录结果以返回可以进一步过滤的新结果?

javascript - 当窗口大小调整为 776px 或更小时,停止 bxslider 上的自动旋转

javascript - Google Site Search 搜索按钮字形图标

javascript - Bootstrap Affix Nav 导致下面的div跳起来

ruby-on-rails - 启动 Ruby on Rails 应用程序时无法通过 AWS Elastic Beanstalk "Congratulations"屏幕

ruby-on-rails - Express Payments rails 模块需要什么样的 PayPal 沙箱帐户?

javascript - 类型错误 : route is undefined and undefined is not an object (evaluating 'route.params' )