以下的js是以周日在哪個(gè)月,則把這個(gè)周歸到哪個(gè)月里面
<html>
<head>
<title>顯示日期調(diào)用</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)));//獲取最后一個(gè)周日
break;}
else
{weeknum++;}
}
lu_showweek.value=weeknum;
lu_showweek_end.value=(end_temp.getFullYear())+"-"+(end_temp.getMonth()+1)+"-"+(end_temp.getDate());
}
else
{
alert("超過當(dāng)前日期了!");
}
}
}
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">個(gè)星期
開始時(shí)間是:<input type="text" id="lu_showweek_begin" size="10" maxlength="10"/>
結(jié)束時(shí)間是:<input type="text" id="lu_showweek_end" size="10" maxlength="10" />
</body>
</html>
更多信息請查看IT技術(shù)專欄