简体   繁体   中英

How to output (date value from PHP) on jQuery ui date/timepicker input field?

For my datetime field I used jQuery date/timepicker.

http://trentrichardson.com/examples/timepicker/

This worked fine.

But on the update form, when I try to output date from database on this date/timepicker input field, it does not work. When I inspect the element the date value is there (in correct ui date/timepicker format) as shown in the image below:

UI日期/时间选择器字段上的输出问题

How can I make date value from PHP appear on datepicker field ?

Instead of setting the value of the generated input field, pass in a defaultValue argument when you're creating the picker. See the Options tab, other options , ie

defaultValue
    Default: null - String of the default time value placed in the input on focus when the input is empty.

This looks like it may only work when selected (eg it says "on focus").

Alternatively, while I'm not familiar with timepicker, you should be able to use the setDate() method to set the date/time, with something like this in a $(document).ready or similiar:

$( ".selector" ).datetimepicker( "setDate", "<?php echo $time_date?>" );

You can not do that. The jQuery Datepicker disables input field value unless it is hardcoded in the field value. If you are using populating from DB or something, use below method. It can be done using setDate function. as follows:-

$( "#your_input_id" ).datepicker( "setDate", "<?php echo $date_value;?>" );

it will work for both date only and date with time fields. It automatically fits to the value that your calender is formatted to.

只需使用PHP的date()函数以与jQuery相同的方式来格式化value属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM