javascript文件
$('#user a').toggle(function(){
//first function here
$('#nav #user-menu').show();
//$('#nav #user .profile, .account, .logout').show();
},
function(){
// second function here
$('#nav #user-menu').hide();
//$('#nav #user .profile, .account, .logout').hide();
});
main.html.erb
<div id="nav">
<% if !session[:user_id] %>
<%= link_to "Please login" , :action => 'login' %>
<%= link_to "Register", :action => 'register'%>
<% else %>
<div id="user"><%= link_to "#{@user.username}"%>
<div id="user-menu">
<div class="profile"><%= link_to "Profile" ,:controller => 'users', :action => 'profile'%></div>
<div class="account"><%= link_to "Account" ,:controller => 'users', :action => 'account'%></div>
<div class="logout"><%= link_to "Logout" , :action => 'logout'%></div>
<div class="clear"></div>
</div>
</div>
</div>
切换用户菜单div可见性工作正常,但点击配置文件,注销和其他链接,他们没有按预期运行,但如果我从javascript删除切换条件和可见性,那么链接工作正常 请帮忙
答案 0 :(得分:0)
尝试更多类似的内容:
var makeVisible = true; // put logic in here to decide whether you want it shown
$("#user-menu").toggle(makeVisible);