对于我的datetime字段,我使用了jQuery date / timepicker。
http://trentrichardson.com/examples/timepicker/
这很好。
但是在更新表单上,当我尝试在此日期/时间戳输入字段上从数据库输出日期时,它不起作用。当我检查元素时,日期值是否存在(正确的ui日期/时间戳格式),如下图所示:
如何从datepicker字段中显示PHP的日期值?
答案 0 :(得分:1)
在创建选择器时,不要设置生成的输入字段的值,而是传入 defaultValue 参数。请参阅Options tab, other options,即
defaultValue
Default: null - String of the default time value placed in the input on focus when the input is empty.
看起来它可能仅在选中时起作用(例如,它表示“焦点上”)。
或者,虽然我不熟悉timepicker,但您应该可以使用setDate() method设置日期/时间,在$(document).ready
或类似的地方设置类似的内容:
$( ".selector" ).datetimepicker( "setDate", "<?php echo $time_date?>" );
答案 1 :(得分:0)
你做不到。除非在字段值中对硬编码进行硬编码,否则jQuery Datepicker将禁用输入字段值。如果您使用DB或其他东西填充,请使用以下方法。可以使用setDate函数完成。如下: -
$( "#your_input_id" ).datepicker( "setDate", "<?php echo $date_value;?>" );
它既适用于日期,也适用于带时间字段的日期。它会自动适合您的日历格式化的值。
答案 2 :(得分:-1)
只需使用PHP的date()
函数来格式化value
属性,就像jQuery一样。