简体   繁体   中英

How can I use link_to to create a “blank” link in Rails 2.3.11?

I just want to create a link that does nothing when it is clicked (other than the jQuery code I am binding to the link's ID.

I am returning "false" in my Javascript function that is bound to the links, but I would just like the link to be "#" or something like that. When I try this:

link_to("Link", "#here")

That gives me the entire current url, plus "#here" stuck on the end.

尝试这个

<%= link_to "TEXT" %>

Try this: <%= link_to('#', :id => 'link_id', :class => 'some_class') %>

Edit

Sorry, I just now saw that this question pertains to Rails 2.3.11. I looked at the api and it looks like it may still work, but if it doesn't, let me know and I'll remove this answer.

您可以尝试这样的事情

<%= "Link", "javascript:void(0)" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM