日期:2014-05-16  浏览次数:20370 次

把某月的日期(包括星期)给表示出来。
例:   输入200707
要把7月1日~7月31日(包括星期)给表示出来。



------解决方案--------------------
改进下显示星期的方式
<input name= "months " >
<input name= "button1 " value= "按 " onclick=show() type= "button ">
<textarea id= "result " style= "width:200;height:200 "> </textarea>
<script language=javascript>
function show()
{
var strDay= "日一二三四五六 "
var str=document.getElementById( "months ").value
re=/^\d{4}\d{2}$/
if(!re.test(str)){
alert( "输入错误 ")
}
var strYear=str.substr(0,4)
var strMonth=parseInt(str.substr(4,2),10)
if((strMonth <1)||(strMonth> 12)){
alert( "输入错误 ")
}
Date.prototype.todateString=function(){
strMonth=parseInt(this.getMonth())+parseInt(1);
strMonth=strMonth.toString()
return this.getYear().toString()+((strMonth.length==1)?( "0 "+strMonth):strMonth)+((this.getDate().toString().length==1)?( "0 "+this.getDate().toString()):this.getDate().toString())
}
var tempDate=new Date(strYear,strMonth-1,1);
var result=new Array();
while(tempDate.getMonth()==(strMonth-1)){
result[result.length]=new Array(tempDate.todateString(), "星期 "+strDay.charAt(tempDate.getDay()));
tempDate=new Date((tempDate/1000+86400)*1000)
}

document.getElementById( "result ").value=result.join( "\n ")
}
</script>