Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改href属性停止Rails和Jquery的功能_Jquery_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

更改href属性停止Rails和Jquery的功能

更改href属性停止Rails和Jquery的功能,jquery,ruby-on-rails,ruby-on-rails-3,Jquery,Ruby On Rails,Ruby On Rails 3,我有一个循环使用的品牌索引,每个品牌都有一个链接,该链接调用一个方法将其添加到表中,并使用jquery将文本加粗 <%= link_to brand.name, { :controller => 'user_favorites', :action => 'create_brand', :brand_id => brand.id, :user_id => current_user.id }, :onclick => "$(this).css('font-weig

我有一个循环使用的品牌索引,每个品牌都有一个链接,该链接调用一个方法将其添加到表中,并使用jquery将文本加粗

<%= link_to brand.name, { :controller => 'user_favorites', :action => 'create_brand', :brand_id => brand.id, :user_id => current_user.id }, :onclick => "$(this).css('font-weight','bold');", :remote => true %>
两件事

  • 我不会改变原来的链接,我会隐藏链接做X和显示链接做Y,这将是一个更不突出和更好的动作切换

  • 我不会用“点击”来做你正在做的事情,我会在点击时触发一个自定义事件,注册到该事件,然后做其他事情。


  • 我很确定这种方法可以解决您的问题,因为您是异步执行的,首先会触发第一个事件(“单击”),然后触发另一个事件,您在jQuery上注册该事件,JavaScript在客户端工作。不是服务器端。查看呈现的HTML(如浏览器所示)以及jQuery脚本会有所帮助。谢谢大卫,我已经用html更新了我的问题。没有jquery脚本,我正在冒昧地调用该方法。您还需要返回响应。在这行“$(this.attr('href',');”之后写入返回true。希望这有帮助。嗨,迪帕克,你是说这个吗?:onclick=>“$(this.css('font-weight','bold');$(this.attr('href',');返回true;”。。。因为这具有相同的结果,即href被更改,但控制器操作不被调用。
    <%= link_to brand.name, { :controller => 'user_favorites', :action => 'create_brand', :brand_id => brand.id, :user_id => current_user.id }, :onclick => "$(this).css('font-weight','bold'); $(this).attr('href', 'http://www.google.com/');", :remote => true %>
    
    <a href="/user_favorites/create_brand?brand_id=1272&amp;user_id=2" data-remote="true" onclick="$(this).css('font-weight','bold'); $(this).attr('href', 'http://www.google.com/');">BrandName</a>