如何执行DatePicker。 [英] How do I execute a DatePicker.

查看:75
本文介绍了如何执行DatePicker。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此示例中的datepicker不起作用。



错误代码:

The datepicker is not working in this example.

Error code:

JavaScript runtime error: Object doesn't support property or method 'datepicker'



代码:


Code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        /* create an array of days which need to be disabled */
        var disabledDays = ["2-21-2010","2-24-2010","2-27-2010","2-28-2010","3-3-2010","3-17-2010","4-2-2010","4-3-2010","4-4-2010","4-5-2010"];

        /* utility functions */
        function nationalDays(date) {
            var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
            //console.log('Checking (raw): ' + m + '-' + d + '-' + y);
            for (i = 0; i < disabledDays.length; i++) {

                if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > date) {
                    //console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
                    return [false];
                }
            }
            //console.log('good:  ' + (m+1) + '-' + d + '-' + y);
            return [true];
        }
        function noWeekendsOrHolidays(date) {
            var noWeekend = jQuery.datepicker.noWeekends(date);
            return noWeekend[0] ? nationalDays(date) : noWeekend;
        }

        /* create datepicker */
        jQuery(document).ready(function() {
            jQuery("#<%=TextBox1.ClientID%>").datepicker({
                minDate: new Date(1900, 0, 1),
                maxDate: new Date(2100, 12, 31),
                dateFormat: 'DD, MM, d, yy',
                constrainInput: true,
                beforeShowDay: noWeekendsOrHolidays
            });
        });
    </script>

推荐答案

.inArray((m + 1) + ' - ' + d + < span class =code-attribute>' - ' + y,disabledDays) = - 1 || new 日期() > 日期){
//console.log('bad:'+(m + 1)+' - '+ d +' - '+ y +'/'+ disabledDays [i]);
返回[false];
}
}
//console.log('good:'+(m + 1)+' - '+ d +' - '+ y);
return [true];
}
函数noWeekendsOrHolidays(date){
var noWeekend = jQuery.datepicker.noWeekends(date);
返回noWeekend [0]? nationalDays(日期):noWeekend;
}

/ * create datepicker * /
jQuery(document).ready(function(){
jQuery(#<% = TextBox1.ClientID %> )。datepicker({
minDate:new Date(1900,0,1) ),
maxDate:new Date(2100,12,31),
dateFormat:'DD,MM,d,yy',
constrainInput:true,
beforeShowDay:noWeekendsOrHolidays
});
});
< / script >
.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > date) { //console.log('bad: ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]); return [false]; } } //console.log('good: ' + (m+1) + '-' + d + '-' + y); return [true]; } function noWeekendsOrHolidays(date) { var noWeekend = jQuery.datepicker.noWeekends(date); return noWeekend[0] ? nationalDays(date) : noWeekend; } /* create datepicker */ jQuery(document).ready(function() { jQuery("#<%=TextBox1.ClientID%>").datepicker({ minDate: new Date(1900, 0, 1), maxDate: new Date(2100, 12, 31), dateFormat: 'DD, MM, d, yy', constrainInput: true, beforeShowDay: noWeekendsOrHolidays }); }); </script>


谁告诉你 jQuery 有这个成员?它没有。你甚至没有包含适当的JavaScript UI库jquery-ui.js,只通过jquery.min.js包含核心jQuery。



用法这里清楚地解释了jQuery datepicker 的代码示例: https://jqueryui.com/ datepicker [ ^ ]。



-SA
Who told you jQuery has this member? It doesn't. You did not even include proper JavaScript UI library, "jquery-ui.js", only included the core jQuery via "jquery.min.js".

The usage of jQuery datepicker is clearly explained here, with a code sample: https://jqueryui.com/datepicker[^].

—SA


这篇关于如何执行DatePicker。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆