【问题标题】:jquery datepair plugin is not workingjquery datepair插件不工作
【发布时间】:2014-04-22 17:48:45
【问题描述】:

我正在使用https://github.com/jonthornton/jquery-datepair

我想在 MVC 应用程序中使用 datepair 示例,但遇到 javascript 错误。

脚本抛出错误:'undefined is not a function'

我做错了什么?

这是我的代码。

查看:

<p id="basicExample">
    <input type="text" class="date start" />
    <input type="text" class="time start" /> to
    <input type="text" class="time end" />
    <input type="text" class="date end" />`enter code here`
</p>

脚本:

$(function () {
    $('#basicExample .time').timepicker({
        'showDuration': true,
        'timeFormat': 'g:ia'
    });

    $('#basicExample .date').datepicker({
        'format': 'm/d/yyyy',
        'autoclose': true
    });

    // initialize datepair
    $('#basicExample').datepair();
});

【问题讨论】:

  • 出于某种原因,我原来的帖子删除了脚本标签。我在参考。 jquery.datepair.js, jquery-2.1.0.js, jquery-ui-1.10.4.js(这是用于日期选择器的), jquery.timePicker.js
  • 检查你的 jquery.js 是否高于其他 js。或$(document).ready(function(){};
  • 我相信 jquery.js 是最新版本。这样,timepicker.js 就无法正常工作。但是,根据github.com/jonthornton/jquery-datepair 文档,datepair.js 可以在没有时间选择器的情况下工作。如果我删除 timepicker.js,我仍然会收到该错误。
  • 我的意思是你放置 .js 文件的顺序,jquery 总是第一个。例如&lt;script src="jquery.js"/&gt;&lt;script src="other.js"/&gt;
  • 我认为问题来自$(function () { 并替换$(document).ready(function(){ //your code here });

标签: javascript jquery jquery-plugins


【解决方案1】:

只需尝试在页脚中添加您的 datepicker 函数脚本并从函数中删除以下行:

 $('#basicExample').datepair();

【讨论】:

    【解决方案2】:

    替换你的$('#basicExample').datepair();

    // initialize datepair
    var datePairElement = document.getElementById('basicExample');
    var datepair = new Datepair(datePairElement);
    

    假设您已为此添加了所有必需的脚本。

    这应该可以。

    【讨论】:

      猜你喜欢
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 2017-01-13
      相关资源
      最近更新 更多