0

我在一个页面中有一个链接,它是一个 rails link_to_remote。当我单击该链接时,它会将我带到页面顶部,URL 中带有“#”。我怎样才能避免这种情况?

= link_to_remote "#{stream_thank_yous_count}" ,:url => add_thankyou_stream_path(stream), :method => :get, :before => "event.preventDefault();", :after => "$('ajaxLoaderDiv').hide();", :html => {:class => "icon-smile-o #{get_count_class(stream_thank_yous_count)}"}

为此生成的 HTML 是

<a id="fav_980209445" class="icon-heart fav" onclick="new Ajax.Request('/streams/980209445/mark_as_favourite?social_inbox=false', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('tHMWDh7R1GZ2t43ejt5aGF4Rds7Jx2nV386JVs5x8wo=')}); $('ajaxLoaderDiv').hide();; return false;" href="#">0</a>

我尝试用 javascript:void(0) 替换 href。使用

$j("a.icon-smile-o,a.icon-heart").attr("href", "javascript:void(0)");

但未能如愿。谁能帮我解决这个问题。

4

2 回答 2

1

试试这个:

$("a.icon-smile-o,a.icon-heart").click(function(e){
    e.preventDefault();
});
于 2014-08-13T06:41:30.223 回答
0
return false;

return false; at the end of the processing document so that the document will not return anything and just passes the value

于 2014-08-13T06:47:50.497 回答