Ruby on Rails - 将输入字段的值传递给
嗨,我被困在这里很糟糕。实际上,senario 非常简单,我有一个像这样的输入字段:
%input.coupon_bar{:type => "text", :name=> "coupon", id=>"coupon_id"}/
我想将该框中的任何值传递给不同的控制器,我试图这样做:
= link_to image_tag("ok_button.png", :border =>0), "/orders/new/", :coupon = #{$('.coupon_bar').val()}
我认为使用 jquery < 会很简单code>$('.coupon_bar').val() 但我想它并不像我想象的那么简单......请帮忙???
哦,与 这个 StackOverFlow 不同问题,我的输入字段不属于任何表单...
提前致谢...
Hi I am stuck here pretty bad. The senario is quite simple actually, I have an input field like this:
%input.coupon_bar{:type => "text", :name=> "coupon", id=>"coupon_id"}/
And I want to pass whatever value is in that box to a different controller, I am trying to do it like this:
= link_to image_tag("ok_button.png", :border =>0), "/orders/new/", :coupon = #{$('.coupon_bar').val()}
I thought it would be simple using the jquery $('.coupon_bar').val()
but I guess its not as simple as I thought... any help please????
Oh, and unlike This StackOverFlow Question, my input field is not part of any form...
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现有两个不好的做法:
不要对链接进行硬编码
尽可能避免干扰性 js
是我的建议:
以下 在你的js中:
I see there two bad practices:
Don't hardcode your links
Avoid obstrusive js when possible
Here is what I suggest:
And in your js:
为什么不直接把它写成表格呢?那会容易得多。
无论如何,您可以使用链接中的 onclick 来实现您的目标:
Why don't you just put it in a form? That would be much easier.
Anyway, you can use the onclick from the link to achieve your goal: