從零開始,laydate的常規使用,並且日期最大不能超過當前日期
阿新 • • 發佈:2018-12-10
laydate的常規使用,分為兩種方式實現日期元件
一、在 layui 模組中使用 下載layui 地址 :https://www.layui.com/ 引入資源路徑 js 和 css
通過下面這樣載入
<input id="birthDate" name="birthDate" class="form-control" >
<script> layui.use('laydate', function(){ var laydate = layui.laydate; //執行一個laydate例項 laydate.render({ elem: '#birthDate', //指定元素 max: getNowFormatDate() }); }); function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } </script> 二、 作為獨立元件使用 下載laydate 地址: https://www.layui.com/laydate/ 引入資源路徑 js就可以了
<input id="birthDate" name="birthDate" class="form-control" >
<script> //執行一個laydate例項 laydate.render({ elem: '#birthDate', //指定元素 max: getNowFormatDate()// 這裡是設定最大日期 }); function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } </script>
對了,不客氣,我的名字叫雷鋒!