jquery datepair插件无法正常工作

时间:2014-04-22 17:48:45

标签: javascript jquery jquery-plugins

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

我想在MVC应用中使用datepair示例,但我收到了javascript错误。

脚本抛出错误:'undefined不是函数'

我做错了什么?

这是我的代码。

查看:

<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();
});

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

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

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

这应该有用。