这就是我的问题。在我的例子中,:onchange函数不起作用,尽管我已经在application.rb中添加了jquery。
在表单中,我需要提醒用户
<%= telephone_field(:user, :phone_country_code, :size => 1, :onchange => "if $('user[phone_country_code]').length > 2 { alert('Your firstname needs to be shorter!'); }") %>在application.html.rb中
<%= javascript_include_tag "jquery" %>在控制台中,我得到了
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2011-09-27 12:36:39 +0530
Served asset /application.js - 304 Not Modified (1ms)发布于 2011-09-27 15:30:16
我认为你的javascript中有一个语法错误。添加括号:
if ($('user[phone_country_code]').length > 2) { alert('Your firstname needs to be shorter!'); }")还有:国家代码的奇怪警报..
https://stackoverflow.com/questions/7565525
复制相似问题