按下按钮后将输入框的值作为参数添加到 URL?

发布于 2024-09-08 08:34:07 字数 222 浏览 2 评论 0原文

我有一个输入字段和 2 个按钮,每个按钮执行不同的功能。我希望其中一个按钮获取输入字段的值并将其添加到按钮应访问的指定 Url(作为参数)。

因此,如果插入到框中的值是“dog”,那么单击按钮后,URL 应该是 "/go_somwhere?value=dog"

我可以只用 html 来完成它还是需要 ruby方法?

我正在使用导轨。

谢谢

I have one input field and 2 buttons, each button performs a different function. i want one of the buttons to take the value of the input field and add it to a specified Url (as a param) that button should go to.

so if the value inserted in to the box is "dog" then after clicking the button the URL should be "/go_somwhere?value=dog"

can i do it in just html or do i need a ruby method?

i'm using rails.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赴月观长安 2024-09-15 08:34:07
<% form_for :item, :url=>{:action=>'go_somwhere'}, :html => { :method=>"get"} do|f| %>

<%= text_field_tag :value, "" %>
<input type="submit" value="Submit" >

<% end %>
<% form_for :item, :url=>{:action=>'go_somwhere'}, :html => { :method=>"get"} do|f| %>

<%= text_field_tag :value, "" %>
<input type="submit" value="Submit" >

<% end %>
‘画卷フ 2024-09-15 08:34:07

看来您需要在客户端通过 javascript 来执行此操作。该按钮应该有一个附加到其单击事件的函数。该函数应该从输入框中读取值并更改 url (window.locations)。

Seems like you would need to do this via javascript on the client side . The button should have a function attached to its click event . This function should read the value from the input box and change the url ( window.locations ) .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文