【问题标题】:Datepicker with default value is today具有默认值的日期选择器是今天
【发布时间】:2021-10-25 11:49:25
【问题描述】:

我有一个页面“nnnx.php”,它有一个日期选择器。日期输入将为:$nnnx = $_POST['nnnx'];

我想要打开 nnnx.php 时,输入的默认值为今天:$nnnx = $today; (= date("Y/m/d")) 当日期选择器值input, $nnnx = $_POST['nnnx'];

(类似这个页面:https://www.history.com/this-day-in-history

你能帮帮我吗?非常感谢!

【问题讨论】:

    标签: php datepicker


    【解决方案1】:

    您需要检查$_POST['nnnx'] 是否存在,然后设置值。您可以使用三元组轻松做到这一点:

    $today = !empty($_POST['nnnx']) ? $_POST['nnnx'] : date('Y-m-d');
    

    【讨论】:

    • 多么简单!但有效。非常感谢!
    【解决方案2】:

    使用null coalescing operator

    $nnnx = $_POST['nnnx'] ?? date('Y-m-d');
    

    【讨论】:

      猜你喜欢
      • 2013-03-03
      • 2019-05-26
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2015-02-09
      • 1970-01-01
      相关资源
      最近更新 更多