繁体   English   中英

是什么原因导致datepicker没有在带有jquery的rails 3.1.3中加载?

[英]What causes datepicker not loading in rails 3.1.3 with jquery?

我们在rails 3.1.3 app中使用jquery非常简单地使用了datepicker。 但是,有两个视图无法加载datepicker。 在所有其他视图上,datepicker加载自己没有问题。 datepicker的所有js代码都在application.js文件中,其中一个(不加载)看起来像这样(带头文件):

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

$(function() {
   $("#src_plant_src_since").datepicker({dateFormat: 'yy-mm-dd'});
});

以下是视图中的简单表单代码:

<%= f.input :src_since, :label => 'start date:', :hint => 'start src date', :as => :string %>

导致datepicker加载一个视图而不是另一个视图的原因是什么? 非常感谢。

的Gemfile

group :assets do
    gem 'jquery-ui-rails'
end

的application.js

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all 
//= require_tree .

或者你只能加载datepicker js。 喜欢:

//= require jquery.ui.datepicker

尝试这个

安装

gem "jquery_datepicker"

这是你的形式

<%= f.label :date %>
 <%= f.datepicker :date, :dateFormat => 'dd MM, yy',  :showOn => "both", :buttonImage => "../assets/calendar.gif", :buttonImageOnly => true, :changeMonth => true, :changeYear => true, :placeholder => "Click on the textfield/Calender" %><br/>

你应该在你的布局中放入application.html

<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" %>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM