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

时间:2015-12-10 12:20:57

标签: javascript jquery date datepicker

大家好,我正在使用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上问了一个问题,但没有得到回复

2 个答案:

答案 0 :(得分:0)

使用

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

}

答案 1 :(得分:0)

浏览我的指定链接并使用其中一个日期选择器,我希望您不会收到此类错误:

Date Picker