如何从jquery datepicker中选择日/月和年

The*_*Guy 7 jquery uidatepicker

我正在使用Jquery UI Datepicker插件,我试图从不同变量的datepicker中获取所选的日,月和年(最终解决方案是将所有3个变量分配给隐藏字段).

这是代码:

        $(function() {
        $("#_StartDate").datepicker(
            {
                 onSelect: function(dateText, inst) {
                    var startDate = new Date(dateText);
                    var selDay = startDate.getDay();
                    alert(selDay);
                 }
            }
        );
    });
Run Code Online (Sandbox Code Playgroud)

我选择了日期"1/10/2011"并返回"1".我选择了日期"1/25/2011",它返回"2".我在这做错了什么?

谢谢你的帮助!

Iva*_*oni 19

getDay返回星期几:)

您可以使用:

getFullYear为年份
getDate当月的一天
getMonth是一年中的一个月

按照完整的getter列表(来自DevDocs):

Date.prototype.getDate()根据本地时间返回指定日期的月中某天(1-31).
Date.prototype.getDay()根据本地时间返回指定日期的星期几(0-6).
Date.prototype.getFullYear()根据本地时间返回指定日期的年份(4位数的4位数).
Date.prototype.getHours()根据本地时间返回指定日期的小时(0-23).
Date.prototype.getMilliseconds()根据本地时间返回指定日期的毫秒数(0-999).
Date.prototype.getMinutes()根据本地时间返回指定日期的分钟数(0-59).
Date.prototype.getMonth()根据本地时间返回指定日期的月份(0-11).
Date.prototype.getSeconds()根据本地时间返回指定日期的秒数(0-59).
Date.prototype.getTime()返回指定日期的数值,作为自1970年1月1日00:00:00 UTC(先前时间为负数)以来的毫秒数.
Date.prototype.getTimezoneOffset()返回当前语言环境的时区偏移量(以分钟为单位).
Date.prototype.getUTCDate()根据通用时间返回指定日期的月份(日期)(1-31).
Date.prototype.getUTCDay()根据通用时间返回指定日期的星期几(0-6).
Date.prototype.getUTCFullYear()根据通用时间返回指定日期的年份(4位数的4位数).
Date.prototype.getUTCHours()根据通用时间返回指定日期的小时数(0-23).
Date.prototype.getUTCMilliseconds()根据通用时间返回指定日期的毫秒数(0-999).
Date.prototype.getUTCMinutes()根据通用时间返回指定日期的分钟数(0-59).
Date.prototype.getUTCMonth()根据通用时间返回指定日期的月份(0-11).
Date.prototype.getUTCSeconds()根据通用时间返回指定日期的秒数(0-59).
Date.prototype.getYear()根据本地时间返回指定日期的年份(通常为2-3位数).请改用getFullYear()**.