jquery 插件 datetimepicker 在打开窗口时将日期设定为当前日期的方法。

<textarea cols="50" rows="15" name="code" class="javascript">$(function() { $(&quot;#start-time&quot;).datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm', beforeShow: getCurrentTime }); $(&quot;#end-time&quot;).datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm', beforeShow: getCurrentTime }); function getCurrentTime() { $(&quot;.ui-datepicker-current&quot;).click(); } });</textarea>

jquery官网上面的datetimepicker,这是使用手动点击按钮的方法来触动当前时间的选择,因为这个库的源码不知道是什么原因只给了当前默认日期的配置,但是没有给定当前时间的配置 。具体简单的配置可以参见他的源码的前面几个default之类的东西。这些基本上很容易看懂基本上就是这个插件的API了。

<textarea cols="50" rows="15" name="code" class="javascript">function DateTimepicker() { this.debug = false; // Change this to true to start debugging this._nextId = 0; // Next ID for a date picker instance this._inst = []; // List of instances indexed by ID this._curInst = null; // The current instance in use this._disabledInputs = []; // List of date picker inputs that have been disabled this._datetimepickerShowing = false; // True if the popup picker is showing , false if not this._inDialog = false; // True if showing within a &quot;dialog&quot;, false if not this.regional = []; // Available regional settings, indexed by language code this.regional[''] = { // Default regional settings clearText: 'Clear', // Display text for clear link clearStatus: 'Erase the current date', // Status text for clear link closeText: 'Close', // Display text for close link closeStatus: 'Close without change', // Status text for close link prevText: '&lt;Prev', // Display text for previous month link prevStatus: 'Show the previous month', // Status text for previous month link nextText: 'Next&gt;', // Display text for next month link nextStatus: 'Show the next month', // Status text for next month link currentText: 'Today', // Display text for current month link currentStatus: 'Show the current month', // Status text for current month link monthNames: ['January','February','March','April','May','June', 'July','August','September','October','November','December'], // Names of months for drop-down and formatting monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting monthStatus: 'Show a different month', // Status text for selecting a month yearStatus: 'Show a different year', // Status text for selecting a year weekHeader: 'Wk', // Header for the week of the year column weekStatus: 'Week of the year', // Status text for the week of the year column dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday dayStatus: 'Set DD as first week day', // Status text for the day of the week selection dateStatus: 'Select DD, M d', // Status text for the date selection dateFormat: 'mm/dd/yy', // See format options on parseDate timeFormat: 'hh:ii', firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ... initStatus: 'Select a date', // Initial Status text on opening isRTL: false // True if right-to-left language, false if left-to-right }; this._defaults = { // Global defaults for all the date picker instances showOn: 'focus', // 'focus' for popup on focus, // 'button' for trigger button, or 'both' for either showAnim: 'show', // Name of jQuery animation for popup defaultDate: null, // Used when field is blank: actual date, // +/-number for offset from today, null for today appendText: '', // Display text following the input box, e.g. showing the format buttonText: '...', // Text for trigger button buttonImage: '', // URL for trigger button image buttonImageOnly: false, // True if the image appears alone, false if it appears on a button closeAtTop: true, // True to have the clear/close at the top, // false to have them at the bottom mandatory: false, // True to hide the Clear link, false to include it hideIfNoPrevNext: false, // True to hide next/previous month links // if not applicable, false to just disable them changeMonth: true, // True if month can be selected directly, false if only prev/next changeYear: true, // True if year can be selected directly, false if only prev/next yearRange: '-10:+10', // Range of years to display in drop-down, // either relative to current year (-nn:+nn) or absolute (nnnn:nnnn) changeFirstDay: true, // True to click on day name to change, false to remain as set showOtherMonths: false, // True to show dates in other months, false to leave blank showWeeks: false, // True to show week of the year, false to omit calculateWeek: this.iso8601Week, // How to calculate the week of the year, // takes a Date and returns the number of the week for it shortYearCutoff: '+10', // Short year values &lt; this are in the current century, // &gt; this are in the previous century, // string value starting with '+' for current year + value showStatus: false, // True to show status bar at bottom, false to not show it statusForDate: this.dateStatus, // Function to provide status text for a date - // takes date and instance as parameters, returns display text minDate: null, // The earliest selectable date, or null for no limit maxDate: null, // The latest selectable date, or null for no limit speed: 'normal', // Speed of display/closure beforeShowDay: null, // Function that takes a date and returns an array with // [0] = true if selectable, false if not, // [1] = custom CSS class name(s) or '', e.g. $.datetimepicker.noWeekends beforeShow: null, // Function that takes an input field and // returns a set of custom settings for the date picker onSelect: null, // Define a callback function when a date is selected onClose: null, // Define a callback function when the datetimepicker is closed numberOfMonths: 1, // Number of months to show at a time stepMonths: 1, // Number of months to step back/forward rangeSelect: false, // Allows for selecting a date range on one date picker rangeSeparator: ' - ' // Text between two dates in a range }; $.extend(this._defaults, this.regional['']); this._datetimepickerDiv = $('&lt;div id=&quot;datetimepicker_div&quot;&gt;&lt;/div&gt;'); }</textarea>

你可能感兴趣的:(jquery,Date,function,null,callback,button)