我正在使用 date input
类型在我的 PHP 项目中选择一个日期。
现在每次提交表单时,我都想在已选择的输入中显示date
。
这是我试过的:
<?php $date = $_GET['date']; ?>
<input placeholder="<?php $date ?>" type="date" name="date" id="date" />
但不幸的是,这似乎不起作用。
有人知道我的目标是否可行吗?
非常感谢!
最佳答案
您不能将占位符设置为 <input type="date"/>
.请参阅 HTML 规范中的以下信息:
The following content attributes must not be specified and do not apply to the element: accept, alt, checked, dirname, formaction, formenctype, formmethod, formnovalidate, formtarget, height, inputmode, maxlength, minlength, multiple, pattern, placeholder, size, src, and width. https://html.spec.whatwg.org/multipage/forms.html#date-state-%28type=date%29
您必须将日期设置为 value
像下面这样:
<?php $date = $_GET['date']; ?>
<input type="date" name="date" id="date" value="<?= $date ?>" />
示例代码:
<input placeholder="2011-01-01" type="date" id="date"/>
<input value="2011-01-01" type="date" id="date"/>
关于php - HTML/PHP 在 html 日期输入中显示当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688388/