加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 未捕获类型错误:$(…).datepicker()不是函数

发布时间:2020-12-17 02:56:32 所属栏目:百科 来源:网络整理
导读:我试图使用jQuery datepicker函数,但我收到一个错误未捕获类型错误:$(…).datepicker()不是一个函数.我已经浏览了我的文件,并没有在application.js中看到对jQuery的双重引用或不正确的文件顺序.有人可以帮助指出可能是什么问题吗? application.html.erb !D
我试图使用jQuery datepicker函数,但我收到一个错误未捕获类型错误:$(…).datepicker()不是一个函数.我已经浏览了我的文件,并没有在application.js中看到对jQuery的双重引用或不正确的文件顺序.有人可以帮助指出可能是什么问题吗?

application.html.erb

<!DOCTYPE html>
<html>
<head>
<%= javascript_include_tag 'application' %>
  <title>MyApp</title>

<meta name="viewport" content="width=device-width,initial-scale=1">

<!-- CSS/Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">


  <%= stylesheet_link_tag 'application' %>
  <%= csrf_meta_tags %>
  <!--  -->
</head>
<body>

  <%= render partial: "shared/top_info" %>

<%= yield %>




<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous">
</script>
<!--  -->
</body>
</html>

的application.js

//= require jquery
//= require jquery_ujs
//= require ahoy
//= require_tree .

$('#customer_drop_off_date').datepicker();

html.erb

<% form_tag('/post') do %>
  <%= text_field_tag(:customer_drop_off_date) %>
<% end %>

的Gemfile

source 'https://rubygems.org'

gem 'rails','4.2.6'
gem 'pg','~> 0.15'
gem 'uglifier','>= 1.3.0'
gem 'jquery-rails'
gem 'jbuilder','~> 2.0'
gem 'sprockets'
gem 'sdoc','~> 0.4.0',group: :doc
gem 'bcrypt','~> 3.1.7'
gem 'devise'
gem 'figaro'
gem 'paperclip','~> 5.0.0.beta1'
gem 'ahoy_matey'
gem 'geocoder'

group :development,:test do
  gem "pry"
  gem "pry-rails"
  gem "pry-stack_explorer"
  gem "pry-byebug"
  gem 'byebug'
end

group :development do
  gem 'web-console','~> 2.0'
  gem 'spring'
end

解决方法

将gem’jquery-ui-rails’包含在gemfile中.

要要求所有jQuery UI模块,请将以下内容添加到application.js:

// =需要jquery-ui

进入你的样式表:

/*
 *= require jquery-ui
 */

Gem docs

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读