使用 jquery 在 datepicker 中设置初始值? [英] Set initial value in datepicker with jquery?

查看:34
本文介绍了使用 jquery 在 datepicker 中设置初始值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 jquery ui datepicker 中设置一个初始值.我尝试了几种不同的方法,但似乎没有显示日期,它是空的.

I'm trying to set an initial value in my jquery ui datepicker. I've tried several different ways, but nothing seems to display the date, it's empty.

var idag = new Date();
$("#txtFrom").datepicker("setDate", idag - 2);
$("#txtTom").datepicker("setDate", idag);
$("#txtFrom").datepicker("refresh");
$("#txtTom").datepicker("refresh");

推荐答案

这个简单的 example 适用于我...

This simple example works for me...

HTML

<input type="text" id="datepicker">

JavaScript

var $datepicker = $('#datepicker');
$datepicker.datepicker();
$datepicker.datepicker('setDate', new Date());

我可以通过简单地查看@手册并阅读对setDate:

I was able to create this by simply looking @ the manual and reading the explanation of setDate:

.datepicker( "setDate" , date )
设置日期选择器的当前日期.新日期可能是一个日期对象或当前日期格式的字符串(例如01/26/2009"),一个从今天起的天数(例如 +7)或一串值和句点('y' 表示年,'m' 表示月,'w' 表示周,'d' 表示天,例如 '+1m+7d') 或 null 以清除所选日期.

.datepicker( "setDate" , date )
Sets the current date for the datepicker. The new date may be a Date object or a string in the current date format (e.g. '01/26/2009'), a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null to clear the selected date.

这篇关于使用 jquery 在 datepicker 中设置初始值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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