使用日期来循环
再使用today.getDay()如果值为6或0 ,6为星期六,0为星期天
就可得出

解决方案 »

  1.   

    我告诉你怎么获得指定某一天的星期几,例子:2002年11月7日,切记月份一定要是当月的月份减一,使用for循环就可以实现
    <script>
    var i=7
    alert(new Date(2002,10,i).getDay())
    </script>
      

  2.   

    用for循环在用getDay()函数判断是否为6或者是0。
      

  3.   

    用FOR循环,同时判断GETDAY()值是否是6或者0,如果是的话,你可以显示出来。
      

  4.   

    <style>
    .rborder{
    border:#cccccc 1 solid;
    border-left-color:white;
    border-top-color:white;
    }
    </style>
    <body ondrag="return false" oncontextmenu="return false" onselectstart="return false">
    <table style="width:150;font-size:9pt;border:1 solid #cccccc;background:#f4f4f4;cursor:default">
    <tr align="center"><td class="rborder" style="color:red">日</td><td class="rborder">一</td><td class="rborder">二</td><td class="rborder">三</td><td class="rborder">四</td><td class="rborder">五</td><td class="rborder">六</td></tr>
    <script language="JScript">
    var DayArray=new Array();
    for(i=0;i<6;i++){
    document.write("<tr align=\"center\">");
    for(j=0;j<7;j++)document.write("<td id=\"Time"+i+""+j+"\" class=\"rborder\"></td>"),DayArray[DayArray.length]="Time"+i+""+j;
    document.write("</tr>");
    }
    </script>
    <select id="YearBox" onchange="ChangeBox(this.value,MonthBox.value)">
    <script language="JScript">
    for(i=1990;i<2010;i++)document.write("<option value=\""+i+"\">"+i);
    </script>
    </select>
    <select id="MonthBox" onchange="ChangeBox(YearBox.value,this.value)">
    <script language="JScript">
    for(i=1;i<13;i++)document.write("<option value=\""+i+"\">"+i);
    </script>
    </select><input type="button" value="今天" onclick="ChangHer()" style="border:1 solid #707888">
    </talbe>
    <script language="JScript" onchange="ChangeBox()">
    function ChangeBox(y,m){
    for(i=0;i<DayArray.length;i++)
    eval(DayArray[i]).innerHTML="";
    for(i=0;i<new Date(y,m,0).getDate();i++)eval(DayArray[i+new Date(y,m-1,1).getDay()]).innerHTML=i+1;
    for(i=0;i<DayArray.length;i++)DayArray[i].slice(5,6)==0?eval(DayArray[i]).innerHTML="<nobr style=\"color:red\">"+eval(DayArray[i]).innerText+"</nobr>":null;
    }
    function ChangHer(){
    for(i=0;i<YearBox.length;i++)if(YearBox.options[i].value==new Date().getYear())YearBox.options[i].selected=true;
    for(i=0;i<MonthBox.length;i++)if(MonthBox.options[i].value==new Date().getMonth()+1)MonthBox.options[i].selected=true;
    ChangeBox(new Date().getYear(),new Date().getMonth()+1);
    for(i=0;i<DayArray.length;i++)eval(DayArray[i]).innerText==new Date().getDate()?eval(DayArray[i]).innerHTML="<nobr style=\"color:blue\">"+eval(DayArray[i]).innerText+"</nobr>":null;
    }
    ChangHer();
    </script>
      

  5.   

    <script>
    function showWeekends(s1,s2){
    var d1=new Date(s1.replace(/-/g,"/")),d2=new Date(s2.replace(/-/g,"/"))
    var sd=d1.getDay(),ln=(d2.getTime()-d1.getTime())/86400000,arr=[];i=0;
    if(sd==0)arr[i++]=0;for(j=6-sd;j<ln;j+=7){arr[i++]=j;arr[i++]=j+1;}return(arr);
    }
    alert(showWeekends("2002-6-1","2003-1-1"))
    </script>