首页 新闻 会员 周边

js本周上周下周

0
悬赏园豆:20 [已解决问题] 解决于 2014-09-12 10:06

两个textbox文本框分别取一周中间的周一和周日,当点击input标签的本周的时候,两个文本分别显示本周的周一和周日。点击上周或者下周的时候显示上周一和上周日或下周一和下周日。当点击上周的时候,再次点击下周显示(示的是本周的下一周的周一和周日{不是文本显示的日期的下一周})下周一和下周日

 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head id="Head1" runat="server">
 3     <title>透析日程表</title> 
 4     <script type="text/javascript" language="JavaScript">
 5         var myDate = new Date();
 6         myDate.setDate(myDate.getDay() == 0 ? myDate.getDate() - 6 : myDate.getDate() - (myDate.getDay() - 1)); //周一 
 7         var predate = new Date();
 8         predate.setDate(predate.getDay() == 0 ? 6 - predate.getDate() : predate.getDate() - (-3 - predate.getDay())); //上周周日 
 9         var sundate = new Date();
10         sundate.setDate(sundate.getDay() == 0 ? sundate.getDate() - 6 : sundate.getDate() - (-3 - sundate.getDay())); //下周周日  
11         
12         function prevArea() {//上周一时间
13             myDate.setDate(myDate.getDate() - 7);
14             form1.dDT.value = myDate.toLocaleDateString(); 
15             
16             predate.setDate(predate.getDate() - 7);
17             form1.dDT1.value = predate.toLocaleDateString();
18         }
19         function nextArea() {//下周一时间
20         
21             
22             myDate.setDate(myDate.getDate() + 7);
23             form1.dDT.value = myDate.toLocaleDateString(); 
24             
25             sundate.setDate(sundate.getDate() + 7); 
26             form1.dDT1.value = sundate.toLocaleDateString();
27         }
28         function getCurarea() {//本周一到本周日
29             var amyDate = new Date();
30             amyDate.setDate(amyDate.getDay() == 0 ? amyDate.getDate() - 6 : amyDate.getDate() - (amyDate.getDay() - 1)); //周一   
31             var acurdate = new Date();
32             acurdate.setDate(acurdate.getDay() == 0 ? acurdate.getDate() - 6 : acurdate.getDate() - (acurdate.getDay() - 1)); //周日 
33             acurdate.setMonth(acurdate.getMonth()); //取得月赋值
34             acurdate.setDate(acurdate.getDate() + 6); //周日
35               form1.dDT.value = amyDate.toLocaleDateString();
36             form1.dDT1.value = acurdate.toLocaleDateString(); 
37         }
38         
39     </script > 
40 </head>
41 <table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="327AC6" > 
42       <tr style ="background-color :#F9F9FB"> 
43                     <td align="right">时间:</td>
44                 <td align="left"> 
45                     <asp:TextBox ID="dDT" runat="server"  onclick="calendardate(this,true);" ></asp:TextBox>  
46                     <asp:TextBox ID="dDT1" runat="server"  onclick="calendardate(this,true);" ></asp:TextBox>&nbsp;  
47                          <input type="button" value="上周时间段" onclick="prevArea();" />
48                         <input type="button" value="本周时间段" onclick="getCurarea();" />
49                         <input type="button" value="下周时间段" onclick="nextArea();" /> 
50                      
51                         </td>
52               </tr >
53 </table>
54 <body  > 
55 
56 </body>
低级菜鸟的主页 低级菜鸟 | 初学一级 | 园豆:163
提问于:2014-09-09 19:57
< >
分享
最佳答案
0
 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="b.aspx.cs" Inherits="TXJiLu_b" %>
 2 
 3 
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head id="Head1" runat="server">
 7     <title>透析日程表</title>
 8  
 9     <script type="text/javascript" language="JavaScript">
10         var myDate = new Date();
11         myDate.setDate(myDate.getDay() == 0 ? myDate.getDate() - 6 : myDate.getDate() - (myDate.getDay() - 1)); //周一
12         var predate = new Date();
13         predate.setDate(predate.getDay() == 0 ? 6 - predate.getDate() : predate.getDate() - (-3 - predate.getDay())); //上周周日
14         var sundate = new Date();
15         sundate.setDate(sundate.getDay() == 0 ? sundate.getDate() - 6 : sundate.getDate() - (-3 - sundate.getDay())); //下周周日 
16 
17         function prevArea() {//上周一时间
18             myDate.setDate(myDate.getDate() - 7);
19             form1.dDT.value = myDate.toLocaleDateString(); 
20             
21             predate.setDate(predate.getDate() - 7); 
22             form1.dDT1.value = predate.toLocaleDateString();
23         } 
24         function nextArea() {//下周一时间
25             myDate.setDate(myDate.getDate() + 7);
26             form1.dDT.value = myDate.toLocaleDateString();
27 
28             sundate.setDate(sundate.getDate() + 7);
29             form1.dDT1.value = sundate.toLocaleDateString(); 
30         }
31 
32 
33         function getCurarea() {//本周一到本周日
34             var amyDate = new Date();
35             amyDate.setDate(amyDate.getDay() == 0 ? amyDate.getDate() - 6 : amyDate.getDate() - (amyDate.getDay() - 1)); //周一
36             
37             var acurdate = new Date();
38             acurdate.setDate(acurdate.getDay() == 0 ? acurdate.getDate() - 6 : acurdate.getDate() - (acurdate.getDay()-1));//周日
39 
40             acurdate.setMonth(acurdate.getMonth()); //取得月赋值
41             acurdate.setDate(acurdate.getDate() + 6); //周日
42 
43             form1.dDT.value = amyDate.toLocaleDateString();
44             form1.dDT1.value = acurdate.toLocaleDateString();
45             document.getElementById("Button2").click();
46 
47         }
48 
49     </script > 
50 </head>
51 <body  > 
52 
53     <form id="form1" runat="server">
54     <div>
55 <table style ="width :98%;"  border="0" align="center" cellpadding="0" cellspacing="0">
56   <tr style ="height :6;">
57     <td></td>
58  </tr> 
59 </table>    
60 <table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="327AC6" >    
61            <tr style ="background-color :#F9F9FB"> 
62                     <td align="right">时间:</td>
63                 <td align="left"> 
64                     <asp:TextBox ID="dDT" runat="server"  onclick="calendardate(this,true);" ></asp:TextBox> --
65                     <asp:TextBox ID="dDT1" runat="server"  onclick="calendardate(this,true);" ></asp:TextBox>&nbsp;  
66                          <input type="button" value="上周时间段" onclick="prevArea();" />
67                         <input type="button" value="本周时间段" onclick="getCurarea();" />
68                         <input type="button" value="下周时间段" onclick="nextArea();" /> 
69                         <asp:Button ID="Button2" runat="server" Text="重置时间" CssClass="hidden" />
70                         </td>
71               </tr >
72 
73       </table> 
74  
75     </div>
76     </form>
77 </body>
78 </html>
低级菜鸟 | 初学一级 |园豆:163 | 2014-09-12 10:04
其他回答(2)
0

上个图片看下你要实现什么样的功能吧,没看明白。

收获园豆:5
Alex_QY1987 | 园豆:1888 (小虾三级) | 2014-09-10 11:03
0
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="../JS/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(function () {
            obaganlestyle(1, 7);
        });
        
        function obaganlestyle(snum,lnum)
        {
            var myDate = new Date();
            var day = myDate.getDay();//返回0-6
            //var today = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
            //当天的日期
            var endday;
            var startday;
          
            endday = getthisDay(-day + lnum); //算得周日
            startday = getthisDay(-day + snum);//算的周一
            
            $("#begintime").val(startday + " 00:00:00");
            $("#endtime").val(endday + " 59:59:59");
        }
        //取得日期
        function getthisDay(day) {
            var today = new Date();
            var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
            today.setTime(targetday_milliseconds); //关键
            var tyear = today.getFullYear();
            var tMonth = today.getMonth();
            var tDate = today.getDate();
            if (tDate < 10) {
                tDate = "0" + tDate;
            }
            tMonth = tMonth + 1;
            if (tMonth < 10) {
                tMonth = "0" + tMonth;
            }
            return tyear + "-" + tMonth + "-" + tDate + "";
        }

        //各种日期取得
        function getdaybytype(type) {
            switch (type) {
                case 1:
                    obaganlestyle(1, 7);
                    break;
                case 2:
                    obaganlestyle(0,-6);
                    break;
                case 3:
                    obaganlestyle(8, 14);
                    break;
                default:
                    break;
            }
        }
    </script>
</head>
<body>
    开始时间:<input type="text" id="begintime" value="" /><br />
    结束时间:<input type="text" id="endtime" value="">
    <input type="button" id="thisweek" onclick="getdaybytype(1)" value="这周" />
    <input type="button" id="onweek" onclick="getdaybytype(2)" value="上一周" />
    <input type="button" id="nextweek" onclick="getdaybytype(3)" value="下一周" />
</body>
</html>

这个你拿去试试吧。应该就是你说的那种。记得引用jquery库。

收获园豆:15
大楚打码人 | 园豆:4313 (老鸟四级) | 2014-09-10 11:54

你这种直接的把上周和下周给限定死了!在上周的基础不能再显示上周的时间,下周不能再显示下周的时间。在能同时显示上周或者下周的时候,再按下周的时候可以显示本周的下一周的时间。

支持(0) 反对(0) 低级菜鸟 | 园豆:163 (初学一级) | 2014-09-10 17:32

@低级菜鸟: 

额。我只能帮你到这里了。

支持(0) 反对(0) 大楚打码人 | 园豆:4313 (老鸟四级) | 2014-09-10 17:35

谢谢你的帮助!我也学习了你的思路!

支持(0) 反对(0) 低级菜鸟 | 园豆:163 (初学一级) | 2014-09-10 17:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册