簡體   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