如何使用今天的日期预填充 jQuery Datepicker 文本框? [英] How do I pre-populate a jQuery Datepicker textbox with today's date?
问题描述
我有一个非常简单的 jQuery Datepicker 日历:
I have a very simple jQuery Datepicker calendar:
$(document).ready(function(){
$("#date_pretty").datepicker({
});
});
当然还有 HTML...
and of course in the HTML...
<input type="text" size="10" value="" id="date_pretty"/>
当用户打开日历时,今天的日期会很好地突出显示给用户,但是如何让 jQuery 在页面加载时使用今天的日期预先填充文本框本身,而无需用户执行任何操作?99% 的情况下,今天的默认日期将是他们想要的.
Today's date is nicely highlighted for the user when they bring up the calendar, but how do I get jQuery to pre-populate the textbox itself with today's date on page load, without the user doing anything? 99% of the time, the today's date default will be what they want.
推荐答案
更新:有报告称这不再适用于 Chrome.
这很简洁并且可以完成工作(已过时):
This is concise and does the job (obsolete):
$(".date-pick").datepicker('setDate', new Date());
这不太简洁,利用 chaining 允许它在 chrome 中工作(2019-06-04):
This is less concise, utilizing chaining allows it to work in chrome (2019-06-04):
$(".date-pick").datepicker().datepicker('setDate', new Date());
这篇关于如何使用今天的日期预填充 jQuery Datepicker 文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!