【问题标题】:Uncaught TypeError: $(...).datepicker is not a function - Bootstrap datepicker未捕获的类型错误:$(...).datepicker 不是函数 - 引导日期选择器
【发布时间】:2017-01-10 00:32:30
【问题描述】:

令人沮丧的错误。我无法轻易从堆栈溢出中辨别出答案,因此求助于发布问题。任何帮助将不胜感激。

我收到此错误:

Uncaught TypeError: $(...).datepicker is not a function
  1. Rails 4.2.4
  2. ruby 2.1.2p95(2014-05-08 修订版 45877)[x86_64-linux]

宝石文件:

gem 'ransack'

gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'

gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'

我的 application.js 文件:

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require turbolinks
//= require jquery-ui/autocomplete
//= require autocomplete-rails
//= require bootstrap-sprockets
//= require moment
//= require bootstrap-datetimepicker
//= require_tree .

我的 application.css.sass 文件:

@import "bootstrap-sprockets"
@import "bootstrap"
@import 'bootstrap-datetimepicker'

这就是我选择日期选择器的方式(在准备好的文档中):

$('#date-form-control1').datepicker({format: 'yyyy-mm-dd'});

这是我的表格:

 <div class="field">
    <%= f.label :invoice_invoice_date_gteq, "Date: Greater than:" %>
    <%= f.text_field  :invoice_invoice_date_gteq, id: "date-form-control1", placeholder: "Date >= to" %>
  </div>

非常感谢任何建议。

【问题讨论】:

  • 加载页面时控制台中是否有任何 javascript 错误?在未捕获类型错误之前:$(...).datepicker 不是函数。看起来日期选择器 js 库没有加载
  • 这是 javascript 错误 - 页面看起来不错。
  • 我怀疑@Deepak 的意思是建议他发布的链接可能会回答您的问题。是吗?
  • @Tass 是的,类似的问题

标签: ruby-on-rails bootstrap-datepicker


【解决方案1】:

如果你只想使用 datepicker 而不是使用 datepiker.js javascript,因为你不能在 datetimepicker.js 中使用 datepicker 函数

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#date-form-control1" ).datepicker({format: 'yyyy-mm-dd'});
  } );
  </script>

【讨论】:

    【解决方案2】:

    你不能用datepicker({mindate})调用datetimepicker

    使用$('#date-form-control1').datetimepicker();

    如果您只想使用日期,请使用日期选择器

    【讨论】:

      猜你喜欢
      • 2020-12-18
      • 2014-09-05
      • 1970-01-01
      • 2016-07-12
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多