以下的js是以周日在哪个月,则把这个周归到哪个月里面
<html>
<head>
<title>显示日期调用</title>
</head>
<script language="javascript">
<!--
function lu_datechange()
{
var lu_shouyear=document.getElementById("lu_shouyear");
var lu_shoumonth=document.getElementById("lu_shoumonth");
var lu_showweek=document.getElementById("lu_showweek");
var lu_showweek_begin=document.getElementById("lu_showweek_begin");
var lu_showweek_end=document.getElementById("lu_showweek_end");
var end_temp="";
var begin_temp2="";
var weeknum="";
var tempnum=0;
if((lu_shouyear.value!="")&&(lu_shoumonth.value!=""))
{
var temp_btime=new Date(lu_shouyear.value+"/"+lu_shoumonth.value+"/1");//获取选择年月的1号
var tempnum=temp_btime.getDay();//获取选择日期的星期几0表示日
if(tempnum==0){tempnum=7}
var temp_now=new Date();
if (!lu_checkdate(temp_now,temp_btime))
{
var begin_temp=(new Date(temp_btime.setDate(temp_btime.getDate()-(tempnum-1))));//获取了开始日期------就是日期开始的
lu_showweek_begin.value=(begin_temp.getFullYear())+"-"+(begin_temp.getMonth()+1)+"-"+(begin_temp.getDate());
begin_temp2=begin_temp;
for (i=1;i<7;i++)
{
begin_temp2=(new Date(begin_temp2.setDate(begin_temp2.getDate()+7)));
if(parseInt(begin_temp2.getMonth()+1)!=parseInt(lu_shoumonth.value))
{end_temp=(new Date(begin_temp2.setDate(begin_temp2.getDate()-8)));//获取最后一个周日
break;}
else
{weeknum++;}
}
lu_showweek.value=weeknum;
lu_showweek_end.value=(end_temp.getFullYear())+"-"+(end_temp.getMonth()+1)+"-"+(end_temp.getDate());
}
else
{
alert("超过当前日期了!");
}
}
}
function lu_checkdate(temp_now,temp_btime)
{
if(temp_now<temp_btime)
{return true;}
else
{return false;}
}
-->
</script>
<body>
<select id="lu_shouyear" style="width:60px;" onchange="lu_datechange();">
<option value="" selected="selected">年份</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
</select>
<select id="lu_shoumonth" style="width:50px;" onchange="lu_datechange();">
<option value="" selected="selected">月份</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>本月共有
<input type="text" id="lu_showweek" size="2" readonly="readonly">个星期
开始时间是:<input type="text" id="lu_showweek_begin" size="10" maxlength="10"/>
结束时间是:<input type="text" id="lu_showweek_end" size="10" maxlength="10" />
</body>
</html>
更多信息请查看IT技术专栏