简体   繁体   English

如何在jQuery ui date / timepicker输入字段上输出(PHP中的日期值)?

[英]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日期/时间选择器格式),如下图所示:

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.

相关问题 如何格式化从jQuery datepicker返回的日期输入值,以匹配mysql DATE字段? - How to format the returned date input value from a jQuery datepicker in order to match mysql DATE field? 如何将时间戳转换为 html 日期输入字段值 PHP - How to convert timestamp to html date input field value PHP 如何根据插入的日期从数据库中获取结果,并使用PHP和jQuery AJAX将其分配给输入字段 - How to get result from database based on date insered and assign it to input field using PHP and jQuery AJAX 如何使用PHP中的三个参数(date date,date to和input field)从mysql数据库获取结果 - how to get results from a mysql database using three parameters like (date from, date to and an input field ) in PHP 从输入类型=“日期”值到Php变量 - FROM input type=“date” value TO a Php variable 如何使用Jquery在动态创建的日期字段中添加日期值 - How to add date value in dynamically created date field using Jquery html和php日期输入字段 - html and php date input field 如何从php获取日期值到jquery变量中? - how do i get a date value from php into a jquery variable? 在Jquery UI datepicker字段中从数据库预过滤日期 - Prefil date from database in Jquery UI datepicker field 如何从当前日期设置输入字段的最大日期 - How to set input field's max date from current date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM