我在这里读了很多书,并从帖子中找出了很多解决方案。这是我的第一个问题。我希望我做得很好。
我正在使用来自以下日期时间本地输入类型:http: jquerymobile.com/demos/1.2.1/docs/Forms/textinputs/
我想用我的数据库中的日期时间预填充它(使用 mysql 和 php)
问题是我在字段中获得一个值并且没有日期时间选择器,或者我没有获得任何值,并且将弹出日期时间选择器。
1.我似乎找不到描述如何预填充它的文档。我在忽略它?2.有人可以帮助我解决这个问题吗?
~=
-=-=-=-=-=~我的测试代码如下。
<div data-role="fieldcontain">
<label for="datetime-l">Datetime local:</label>
<input type="datetime" name="datetime-l" id="datetime-l" value="<?php
$date1 = new Datetime($rrecord->strval('datenote'));
echo $date1->format(DateTime::ISO8601);
?>" />
</div>
<div data-role="fieldcontain">
<label for="datetime-2">Datetime local:</label>
<input type="datetime-local" name="datetime-2" id="datetime-2" value="<?php echo $rrecord->strval('datenote') ?>" />
</div>
第一个字段填充了日期,但在触摸它时不会弹出日期时间选取器。
查看链接的屏幕截图 -- http://picpaste.com/2013-09-12_21.45.11_1.png
第二个字段为空,但触摸时会弹出日期时间选取器。
查看链接的屏幕截图 -- http://picpaste.com/2013-09-12_21.45.19.png
这是回显输入的调试代码。它们显示在第一个屏幕截图上。
<?php echo "debug datetime prefill from database"; ?>
<?php
echo "<br/>rrecord strval('datenote') = ", $rrecord->strval('datenote');
$date1 = new DateTime($rrecord->strval('datenote'));
echo "<br/> date1 format(DateTime::ISO8601) = ", $date1->format(DateTime::ISO8601);
?>
我能够使用手机输入日期时间。我查看了输出日期时间格式。格式为"Y-m-d''TH:i"。下面我相应地格式化了 PHP 的输入日期。
<div data-role="fieldcontain">
<label for="datetime-l">Date:</label>
<input type="datetime-local" name="datetime-l" id="datetime-l" value="<?php
echo date("Y-m-d'TH:i", strtotime($rrecord->strval('datenote')));
?>" />
</div>
这行得通。
$(document).ready(function() {
$("#datetime-1").val(<?php YOUR CODE ?>);
$("#datetime-2").val(<?php YOUR CODE ?>);
});
它有点笨拙,但它应该可以工作,只需确保日期的格式是jq mobile所期望的。