js-選取日期間不能超出當前日期
阿新 • • 發佈:2019-01-01
//獲取當前時間,格式YYYY-MM-DD function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var year = date.getFullYear(); 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 = year + seperator1 + month + seperator1 + strDate; return currentdate; } function CompareDate(d1,d2) { return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/")))); } var now= getNowFormatDate(); var sj = $('#sj').val(); var flag=CompareDate(sj,now); if(flag){ layer.alert('請選擇正確的日期'); }else{ //重新獲取echarts資料 }