Rails:使用link_to 建立一个没有href 的链接 [英] Rails: using link_to to make a link without href

查看:32
本文介绍了Rails:使用link_to 建立一个没有href 的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 link_to 助手创建没有 href 属性的链接?我想为一个 javascript 操作专门创建一个链接,我不希望它重新加载页面或任何东西.

How can I use the link_to helper to make a link without an href attribute? I want to make a link exclusively for a javascript action, I don't want it reloading the page or anything.

当我省略 url 参数时,单击链接会重新加载页面.同样提供 nil 代替 url.

When I omit the url parameter, clicking the link reloads the page. Ditto for providing nil in place of the url.

推荐答案

我使用这种方法:

= link_to('Click me', 'javascript:;', :id => :foo)

它基本上是一个 Javascript no-op

Its basically a Javascript no-op

这篇关于Rails:使用link_to 建立一个没有href 的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆