交叉日期选取器问题默认值应为空

Cross Date Picker issue default value should be blank

本文关键字:默认值 问题 日期 选取      更新时间:2023-09-26

大家好,我正在使用github的交叉日期选择器代码就像这个

 <?php 
            $date = date("j",strtotime($details['founded'])); // date fetched
            $month = date("n",strtotime($details['founded']));
            $year = date("Y",strtotime($details['founded']));        
                    ?>

HTML

  <input type="date" data-initial-day="<?=$date?>" data-initial-year="<?=$year?>" data-initial-month="<?=$month?>" class='TEx_About_allihh' name="estdate" required/>

JS-

<script>  $("input[type='date']").cdp();</script>

the src of github is https://github.com/lcnvdl/cross-datepicker

当php日期、月份和年份变量中有值时,一切都很好,但当它们为空时,我希望它们显示默认值,如日期、月份、年份

现在它显示为空白或1。

有时我也希望他们不要有任何价值。

如果你知道如何实现这一点,请告诉我,我也在github上问了一个问题,但没有得到回应

通过我给定的链接并使用其中一个日期选择器,我希望你不会得到这种错误:

日期选择器

使用将成为的null coalescing operator

https://wiki.php.net/rfc/isset_ternary

$temp = (date("j",strtotime($details['founded'])); //try to convert array element to time
if ($details['founded'] != "") { //check if it isn't an empty string
    $date = $temp ?? strtotime("now"); //set it to the converted time or set it to the current time
} else {
strtotime("now"); //fallback for an empty string

}