代码如下:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script src="datePicker/WdatePicker.js"></script>
<script src="jquery-1.7.1.min.js"></script>
<script>
//判断是否为工作日
function isWorkday(date) {
//var date = !date ? new Date() : new Date(date);
var date=new Date(date);
var getday = date.getDay();
if (getday == 0 || getday == 6) {
return false; //不是返回False
}
else {
return true;
}
}
//获取Date对象的年月日xxxx-xx-xx
function dateToyymmdd(d){
var month=d.getMonth()+1;
var day = d.getDate();
if(month<10){
month = "0"+month;
}
if(day<10){
day = "0"+day;
}
var val = d.getFullYear()+"-"+month+"-"+day;
return val;
}
//往前推5天除去工作日
function back(date){
var i=0;
var d=new Date(date);//获取传入的时间
while(i<5)
{
d.setDate(d.getDate()-1);//获取前一天时间
var val=dateToyymmdd(d);
//alert(isWorkday("2017-7-30")) ;
//alert(val+""+isWorkday(val));
if(isWorkday(val))
{
i++;
}
continue;
}
var val = dateToyymmdd(d);
return val;
}
window.onload=function(){
$("#btn").blur(function(){
var v=$("#btn").val();
$("#label1").html(back(v));
})
}
//alert(back('2017-08-02'));
</script>
<body>
<input type="text" name="btn" id="btn" onclick="WdatePicker()">
<br>
<br>
<br>
<br>
<label id="label1" ></label>
</body>
</html>