Javascript 如果用户未登录,rails jquery弹出窗口
如果用户在站点上停留了一定的时间(测试时间为3秒),但他们没有登录,则尝试使用一个简单的弹出框 它工作正常,但即使用户登录,它仍然会弹出,这不应该发生 HAML:Javascript 如果用户未登录,rails jquery弹出窗口,javascript,jquery,ruby-on-rails,coffeescript,haml,Javascript,Jquery,Ruby On Rails,Coffeescript,Haml,如果用户在站点上停留了一定的时间(测试时间为3秒),但他们没有登录,则尝试使用一个简单的弹出框 它工作正常,但即使用户登录,它仍然会弹出,这不应该发生 HAML: .signuppopup{:id => if current_user then "user_id#{current_user.id}" else "user_id#{0}" end} %h1 You've been browsing the site for a while, why not sign up? 共同脚本:
.signuppopup{:id => if current_user then "user_id#{current_user.id}" else "user_id#{0}" end}
%h1 You've been browsing the site for a while, why not sign up?
共同脚本:
signupPopUp = ->
$(".signuppopup").css "display", "block" unless $("#user_id").val() is 0
return
setTimeout signupPopUp, 3000
当我在console.log中记录$(“#user_id”).val()时,它总是说它是未定义的,即使在我登录时也是如此
css(不是问题):
用于设置
:id
的haml
代码不正确;因此它没有被设置,因此$(“#user_id”).val()
在所有情况下都计算为未定义
尝试:
哈默:
咖啡脚本:
signupPopUp = ->
$(".signuppopup").css "display", "block" if $("#signed_in").length > 0
return
setTimeout signupPopUp, 3000
非常感谢。除了一些小的改动外,这起到了作用,首先将HAML简化为.signuppopup{:id=>(除非当前用户然后“not#signed_in”end)},然后咖啡需要是if$(“#not#signed_in”)。长度>0乐于帮助:-)对,应该是
除非$(“#signed#in”)。长度>0
在我的回答中。
.signuppopup{:id => (if current_user then "signed_in" else "not_signed_in")}
%h1 You've been browsing the site for a while, why not sign up?
signupPopUp = ->
$(".signuppopup").css "display", "block" if $("#signed_in").length > 0
return
setTimeout signupPopUp, 3000