.datepicker('setdate') 问题,在 jQuery 中 [英] .datepicker('setdate') issues, in jQuery

查看:24
本文介绍了.datepicker('setdate') 问题,在 jQuery 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,它执行查询以根据使用 .datepicker() 选择的特定日期范围获取一些数据.我正在尝试将响应数据中的日期选择器设置回执行查询之前选择的日期范围.

I have a function that executes a query to get some data based on a certain date range which is selected using .datepicker(). I am trying to set the datepicker's that are in the response data back to the date range which was selected before the query was executed.

queryDate = '2009-11-01';
$('#datePicker').datepicker('setDate', queryDate);

将日期选择器设置为今天的日期有一个有趣的结果!如果它只是吐出一个错误,我就不会那么困惑.为什么将其设置为今天的日期?

has the interesting result of setting the datepicker to today's date! I wouldn't be so confused if it just spit out an error. Why does it set it to today's date?

如何获取格式为yyyy-mm-dd"的日期并将日期选择器设置为它?

我认为最好将日期选择器链接到的文本框设置为queryDate".

I am thinking it might be best to just set the text-box which the datepicker is linked to to 'queryDate'.

推荐答案

如果您想支持非常老的浏览器,您应该解析日期字符串,因为使用带有 Date 构造函数的 ISO8601 日期格式IE9 之前不支持:

If you would like to support really old browsers you should parse the date string, since using the ISO8601 date format with the Date constructor is not supported pre IE9:

var queryDate = '2009-11-01',
    dateParts = queryDate.match(/(d+)/g)
    realDate = new Date(dateParts[0], dateParts[1] - 1, dateParts[2]);  
                                    // months are 0-based!
// For >= IE9
var realDate = new Date('2009-11-01');  

$('#datePicker').datepicker({ dateFormat: 'yy-mm-dd' }); // format to show
$('#datePicker').datepicker('setDate', realDate);

检查上面的例子这里.

这篇关于.datepicker('setdate') 问题,在 jQuery 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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