Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Microsoft JScript运行时错误:对象不支持属性或方法“datepicker”_Javascript_Jquery_Datepicker - Fatal编程技术网

Javascript Microsoft JScript运行时错误:对象不支持属性或方法“datepicker”

Javascript Microsoft JScript运行时错误:对象不支持属性或方法“datepicker”,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,我正在使用jquery datepicker并调用一个名为customRange的自定义函数 如果没有这个函数,datepicker工作得非常好 在函数运行时,我在以下位置出现错误: if ($("#EndDate").datepicker("getDate") != null) { Microsoft JScript运行时错误:对象不支持属性或方法“datepicker” 为什么会这样 $('#StartDate, #EndDate').datepicker({ //

我正在使用jquery datepicker并调用一个名为customRange的自定义函数

如果没有这个函数,datepicker工作得非常好

在函数运行时,我在以下位置出现错误:

if ($("#EndDate").datepicker("getDate") != null) {
Microsoft JScript运行时错误:对象不支持属性或方法“datepicker”

为什么会这样

    $('#StartDate, #EndDate').datepicker({
        //dateFormat: 'dd/mm/yy',
        hourMin: 9,
        hourMax: 17,
        //minDate: '0',
        beforeShowDay: $.datepicker.noWeekends,
        beforeShow: customRange,
        firstDay: 1,
        changeFirstDay: false,

    });

    function customRange(input) {
        var min = new Date(2008, 11 - 1, 1), //Set this to your absolute minimum date
            dateMin = min,
            dateMax = null,
            dayRange = 6; // Set this to the range of days you want to restrict to

        if (input.id === "StartDate") {
            if ($("#EndDate").datepicker("getDate") != null) {
                dateMax = $("#EndDate").datepicker("getDate");
                dateMin = $("#EndDate").datepicker("getDate");
                dateMin.setDate(dateMin.getDate() - dayRange);
                if (dateMin < min) {
                    dateMin = min;
                }
            }
            else {
                dateMax = new Date; //Set this to your absolute maximum date
            }
        }
        else if (input.id === "EndDate") {
            dateMax = new Date; //Set this to your absolute maximum date
            if ($("#StartDate").datepicker("getDate") != null) {
                dateMin = $("#StartDate").datepicker("getDate");
                var rangeMax = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + dayRange);

                if (rangeMax < dateMax) {
                    dateMax = rangeMax;
                }
            }
        }
        return {
            minDate: dateMin,
            maxDate: dateMax
        };
    }

如果还没有完成,或者无法从代码中判断,那么jQuery应该包装在文档就绪事件中,以确保在文档就绪后运行

较新的语法是:

例如 否则beforeShow触发得太早,包括jQueryUI在内的任何东西都无法使用

这个JSFIDLE似乎可以与打包在startup中的现有代码配合使用:


您是否按照正确的顺序包含了jQuery和jQuery UI?jQuery先行。

我希望不会太晚:-


链接非常有用-

是的,当然,正如我提到的,如果没有customRange函数datepicker,datepicker本身就可以正常工作对不起,它是asp.net mvc视图中的一个脚本是的,但是jQuery执行是在加载文档之后发生的吗?e、 g.包装在$function{do my work here}中;?不,它不是,如果我尝试将它包装到一个函数中,我从一开始就会遇到相同的错误,即使没有自定义函数,datepicker也不会运行。是否包含jQuery UI?仍然不适用于我,我想我应该在asp.NETMVC中运行它view@Wizeman1986:如果您能够发布输出的完整HTML页面,则应该很容易发现问题。在MVC中运行jQuery没有什么特别之处,因为MVC纯粹是一个HTML生成器。
 $(function(){
    $('#StartDate, #EndDate').datepicker({
        //dateFormat: 'dd/mm/yy',
        hourMin: 9,
        hourMax: 17,
        //minDate: '0',
        beforeShowDay: $.datepicker.noWeekends,
        beforeShow: customRange,
        firstDay: 1,
        changeFirstDay: false,

    });
  });