[英]How to output (date value from PHP) on jQuery ui date/timepicker input field?
For my datetime field I used jQuery date/timepicker. 对于我的datetime字段,我使用了jQuery date / timepicker。
http://trentrichardson.com/examples/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 ? 如何使PHP的日期值显示在datepicker字段上?
Instead of setting the value of the generated input field, pass in a defaultValue argument when you're creating the picker. 在创建选择器时,请传递defaultValue参数,而不是设置生成的输入字段的值。 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: 另外,虽然我对时间选择器不熟悉,但是您应该能够使用setDate()方法设置日期/时间,并在$(document).ready
或类似名称中进行如下设置:
$( ".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. jQuery Datepicker禁用输入字段值,除非将其硬编码在字段值中。 If you are using populating from DB or something, use below method. 如果您正在使用从数据库或其他方式进行填充,请使用以下方法。 It can be done using setDate function. 可以使用setDate函数完成。 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
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.