我有一个用户页面,用户列出他的追随者和他关注的用户。如果他点击一个按钮,它会显示追随者。如果他点击另一个按钮,它会显示他的跟随用户。jquery事件只发射第二次点击 - 为什么?
我不明白jquery事件第二次触发,而不是第一次触发。我在show.html.erb中设置了用户“关注”列表。这里是匹配show.js.erb:
$(function(){
$("#trusts_list_button").click(function(){
$("#relationship_list").html("<%= escape_javascript(render 'follows') %>");
});
$("#trusted_list_button").click(function(){
$("#relationship_list").html("<%= escape_javascript(render 'followers') %>");
});
});
这里是节目的看法:
<%= @user.name %>
<%= link_to "Add friends", facebook_friends_user_path %>
<table><tr><td>
<%= link_to "Trusts", "#follows", :id => "trusts_list_button", :remote => true%></td>
<td><%= link_to "Trusted by", "#followers" , :id => "trusted_list_button", :remote => true %></td></tr></table>
<div id = "relationship_list"><%= render 'follows' %></div>
第一次点击后,则这两个按钮正常工作。但是,第一次初步点击确实让我失望。 我会很感激任何帮助;这不是我第一次遇到JQuery问题,而且我对修复这种简单问题感到茫然。
嗨Sudhir ...你是什么意思?每个功能都与不同的项目有关。 – Laurent 2013-03-04 07:15:40
':remote => true'有什么意义? – apneadiving 2013-03-04 07:39:14
@apneadiving我刚刚删除:remote => true并猜测是什么? JQuery完全停止响应。我认为:remote => true恰恰是为了发挥JQuery的作用。 – Laurent 2013-03-04 07:41:43