选择 年 月 日后 计算出该月共有几周,动态显示在select中

关键字:my97 、当前月周总数

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>

<script type="text/javascript" src="js/calendar/WdatePicker.js"></script>

</head>

<body>

<td>当前日期:</td>

<td><input name="startdate" id="startdate" type="text"   onFocus="WdatePicker({isShowWeek:true,onpicked:function() {abc();}})"/></td>

<td>请选择周:</td>

<select id="weeksum"></select>

</body>

</html>

 

 

<SCRIPT LANGUAGE="JavaScript">

function abc() {
 $("#weeksum").html("");
 var selectdate =$("#startdate").val().split("-");
 
 var a=selectdate[0];
 var b=selectdate[1];
 
 var c=1;
 var date = new Date(a, parseInt(b) - 1, 1), w = date.getDay(), d = date.getDate();
 //return Math.ceil( (d + 6 - w) / 7 );

var date = new Date();
date.setFullYear(a);
date.setMonth(b);//当前月-1
date.setDate(1);
var weeknumber = date.getDay();//该月第一天是星期几
//alert(weeknumber);
var monthday=30;
//weeknumber+当前月的天数/7
if(a== 1 || a==3 || a== 5 || a==7 || a==8 ||a==10 ||a== 12){//每月多少天
 monthday=31;
}
if(a==4 ||a==6 ||a== 9 ||a== 11){
 monthday=30;
}
if((a%4==0 && a%100 != 0) || (a%400==0)){
 monthday=29;
}
if(!(a%4==0 && a%100 !=0) || (a%400==0)){
 monthday=28;
}

//当前月的周数
var weeksum=Math.floor((weeknumber+monthday)/7);//每月多少周,小数舍去了
if((weeknumber+monthday)/7   >  Math.floor((weeknumber+monthday)/7)){//如果有小数 总数+1
 weeksum +=1;
}

if(weeksum>0){
 for(i=1;i<=weeksum;i++){
    $("#weeksum").append("<option  value='"+i+"' >" +"第"+i+"周"+"</option>");
   }
}

}

</SCRIPT>

你可能感兴趣的:(html,c,Date,XHTML,function)