我正在使用JQueryUI datepicker。我目前正在使用以下内容:
$('#dtpicker').datepicker('getDate');
从datepicker获取日期。如果用户未在选择器中选择任何日期,则此功能默认为我今天的日期。是否有某些功能可以获取用户选择的日期?例如,如果用户选择了今天的日期,则该函数应返回今天的日期。如果他没有选择任何日期,那么这个函数应该返回false。
我希望此功能用于验证当前不支持的JQueryUI daterangepicker中的日期范围。
答案 0 :(得分:2)
请参阅jQuery UI docs。在代码中:
.datepicker("getDate");
返回datepicker的当前日期,如果没有选择日期,则返回null。我刚刚在jQuery UI文档上提供的演示框上运行了这个方法。来自firebug控制台的文字:
[没有设定日期]
>>> $("#datepicker").datepicker("getDate");
null
[然后我使用datepicker将日期设置为明天]
>>> $("#datepicker").datepicker("getDate");
Tue Apr 06 2010 00:00:00 GMT+1200 (New Zealand Standard Time) {}
这就是你想要的吗?
答案 1 :(得分:1)
daterangepicker由两个自动生成的日期选择器组成。开始日期datepicker的类别为“range-start”,而end datepicker的类型为“range-end”。
因此,访问getDate函数非常简单:
$(".range-start").datepicker("getDate");
$(".range-end").datepicker("getDate");
在Firefox中测试过,对我很有帮助。伟大的插件顺便说一句!