开发者

Basic jQuery with Rails

I was trying to use jQuery in Rails. I'm having a problem getting started off. I need to attach a jQuery function. Suppose, I have this link_to helper

<%= link_to "Sign in", :id => "user_sign_in" %>

I need to show a popup window when a user clicks this link. What do I write in my application.js file? This is what I have so far, but it's 开发者_如何学Pythonnot working: jQuery(function(){ $("#user_sign_in").live("click", function(){ alert('I'm hit') }) };)

Please suggest!


As @Augusto has said, firstly you need to escape the single quote in I'm, unless you change to the double quotes wrapping that string.

Secondly, the semi-colon at the end of that example should go after the last parenthesis.

This all assumes you even have jQuery installed, which you can double-check by looking at public/javascripts directory and verifying that jquery.js is present, as well as making sure that your application layout in views/layouts directory includes it.

If this answer has helped you solve the problem, accept it which will improve your accept rate. Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜