【问题标题】:Timepicker : Uncaught TypeError: undefined is not a functionTimepicker:未捕获的类型错误:未定义不是函数
【发布时间】:2014-05-25 14:53:11
【问题描述】:

这个插件有点麻烦:https://github.com/jdewit/bootstrap-timepicker

//= require jquery
//= require jquery_ujs
//= require bootstrap-datepicker/js/bootstrap-datepicker
//= require bootstrap-timepicker/js/bootstrap-timepicker
//= require admin/fileupload
//= require admin/category
//= require admin/cars
//= require admin/restaurants
//= require admin/events
//= require zipcodes

在 admin/events.js 中:

$(document).ready(function(){
  $('.timepicker').timepicker();
});

我得到了这个错误: Uncaught TypeError: undefined is not a function

谁能帮帮我?

编辑:

这是我使用 console.log($) 得到的:

function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        // Need init if jQuery is called (just allow error to be thrown if not included)
        return new jQuery.fn.init( selector, context );
    } VM13723:2
undefined

【问题讨论】:

  • 你是否包含了 bootstrap-timepicker.js?
  • Yes // 需要 bootstrap-timepicker/js/bootstrap-timepicker 是 bootstrap-timepicker.js 的声明(在 RoR 中)
  • 你的元素$('.timepicker')是否加载了ajax?
  • 如果你只做console.log($)console.log(jQuery)呢?
  • 你的 JQuery 是什么版本?

标签: javascript jquery ruby-on-rails twitter-bootstrap


【解决方案1】:

我遇到了这个问题,我已经解决了:
首先,您必须通过 NuGet 包管理器安装 jQuery UI。
如果您没有它,请搜索如何将“jQuery UI 添加到 ASP.NET MVC”
1- 转到“http://www.sitepoint.com/10-jquery-time-picker-plugins/” 并选择其中一个时间选择器。
2-下载包(右键单击js和css文件并选择 “另存为链接”)。
3-在脚本中拖放“(timepicker js文件的名称).js” 项目解决方案资源管理器中的文件夹。
4-在脚本中拖放“(timepicker css文件的名称).css” 项目解决方案资源管理器中的 content\themes\base\ 文件夹。
5- 转到“BundleConfig”并添加(timepicker js 文件的名称).js 到 你的“~/bundles/jqueryui”和ether add(timepicker css文件的名称).css 到“~/Content/themes/base/css”
希望对你有用

【讨论】:

    猜你喜欢
    • 2015-03-14
    • 2014-12-13
    • 2014-08-11
    • 2015-04-14
    相关资源
    最近更新 更多