0

大家好,我正在尝试在 jQuery 中设置 datepicker 控件的日期。当我通过 Mozilla Firefox 浏览器运行该页面时,它工作正常。但是,当我在 Google Chrome 中运行它时,日期没有设置。有谁知道问题是什么?

cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
var myDate = new Date(cookie_value);
var date1 = new Date(Date.parse(myDate));
date1.setDate(date1.getDate());
var newDate = date1.toDateString();
newDate = new Date(Date.parse(newDate));
var option = "minDate";

$("#ctl00_ContentPlaceHolder1_txtArrivalDate").datepicker("option", option, newDate);
// $("#ctl00_ContentPlaceHolder1_txtArrivalDate").datepicker("option", option, newDate);
$("#ctl00_ContentPlaceHolder1_txtDepartureDate").datepicker('setDate', newDate);
4

1 回答 1

0

您的许多代码似乎是多余的。为什么 date1=new Date(....) 然后 date1.setDate(...)?如果 newDate 只是 date1 的副本,为什么还要创建它?

见:http: //jsfiddle.net/QB6K6/

使用下面的代码,它适用于我的 chrome。不过,这取决于您的 cookie 的价值。

$(document).ready(function () {

var cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
var myDate = new Date(cookie_value);

$("#ctl00_ContentPlaceHolder1_txtArrivalDate").datepicker( {minDate:myDate});

$("#ctl00_ContentPlaceHolder1_txtDepartureDate").datepicker();
$("#ctl00_ContentPlaceHolder1_txtDepartureDate").datepicker("setDate", myDate);

});
于 2013-10-23T12:21:29.587 回答