You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置jQuery Datepicker以选中当前日期?

Hey there! To get your jQuery Datepicker to default to the current date instead of tomorrow, you just need to tweak one line in your configuration. Here's the updated code and breakdown:

Updated Code

HTML (no changes needed here)

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

JavaScript (modified line highlighted)

<script> 
  $( function() { 
    $( "#datepicker" ).datepicker({ 
      dateFormat: 'mm-dd-yy', 
      minDate: "today", 
      maxDate: "+30d", 
      setDate: "today" // Replaced "+1d" with "today"
    }); 
  }); 
</script>

Alternative Explicit Option

If you prefer using a native JavaScript date object instead of the built-in shortcut, you can also set setDate to new Date():

setDate: new Date()

What Changed & Why It Works

  • The original code used "+1d" for setDate, which adds one day to the current date (hence selecting tomorrow).
  • Switching to "today" uses jQuery UI Datepicker's built-in shortcut to select the current date by default.
  • Your existing minDate: "today" setting ensures users can't pick dates before today, which aligns perfectly with the default current date selection.

内容的提问来源于stack exchange,提问作者omkar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 11:32:43