设为首页   加入最爱           最新更新:全方位英文文章资料库
 
资料坊搜索: 标题 全文     
利用JavaScript实现时间段的查询
   首页>>YesizeCOM>>电脑技能坊>>Javascript>>正文       
 
广告招租,e-mail:yesize@hotmail.com

广告招租,e-mail:yesize@hotmail.com


以后,要是做时间段的查询就方便了,不过就是程序有点多,呵呵!

希望大家能帮我测试一下,输入的时间格式是1999-01-01或2000-10-01或2000-10-10,即月份和时间必须是两位,为了方便大家测试,把所有文件放在这里,只要运行time_main.asp就可以了,多谢了!



time_main.asp

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>

<FRAMESET ROWS="82,18" border=1>
    <FRAME NAME="time" SRC="time.asp">
    <FRAME NAME="time_search" SRC="time_search.asp">
</FRAMESET>
<NOFRAMES>您的浏览器不支持FRAMES</NOFRAMES>

</HTML>




time.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<%
    starttime = Request.Form("starttime")
    endtime = Request.Form("endtime")
    
    Response.Write starttime&"<br>"
    Response.Write endtime&"<br>"
    
%>
请点击“查询”按钮

</BODY>
</HTML>


time_search.asp
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<center>
<form name="tform" method="post">
按时间(以<font color=red>[YYYY-MM-DD]</font>格式输入):
<input type="text" name="starttime" size=10 maxlength=10 value="1999-01-02">到
<input type="text" name="endtime" size=10 maxlength=10 value="2000-01-01">
<input type="button" name="tsearch" value="查  询" onclick="return tcheck()">
</form>
</center>

<script language="javascript">
<!--
    function tcheck()
    {
        if (window.document.tform.starttime.value != "")
        {
            var vDate,vYear,vMonth,vDay;
            vDate = window.document.tform.starttime.value;
            vYear = vDate.substring(0,4);
            if (isNaN(vYear) || vYear < 1900)
            {
                window.alert("您的日期1输入有误!");
                tform.starttime.focus();
                return false;
            }
            vMonth = vDate.substring(5,7);
            if (isNaN(vMonth) || vMonth < 01 || vMonth > 12)
            {
                window.alert("您的日期1输入有误!");
                tform.starttime.focus();
                return false;
            }
            vDay = vDate.substring(8,10);
            if (isNaN(vDay) || vDay == "" || vDay.length != 2 || vDay < 01 || vDay > 31)
            {
                window.alert("您的日期1输入有误!");
                tform.starttime.focus();
                return false;
            }
            
            if (vMonth == 04 || vMonth == 06 || vMonth == 09 || vMonth == 11)
            {
                if (vDay > 30)
                {
                    window.alert("您的日期1输入有误!");
                    return false;
                }
            }
            
            if (vMonth == 02)
            {
                if (vYear % 4 == 0 && vYear % 100 || vYear % 400 == 0)
                {
                    if (vDay > 29)
                    {
                        window.alert("您的日期1输入有误!");
                        tform.starttime.focus();
                        return false;
                    }
                }
                else
                {
                    if (vDay > 28)
                    {
                        window.alert("您的日期1输入有误!");
                        tform.starttime.focus();
                        return false;
                    }
                }
            }
            
            
            
            if (vDate.substring(4,5) !== "-" || vDate.substring(7,8) != "-")
            {
                window.alert("您的输入有误,请以YYYY-MM-DD格式输入!");
                tform.starttime.focus();
                return false;
            }
            
            
            if (window.document.tform.starttime.value != "" && window.document.tform.endt
ime.value != "")
            {
                if (window.document.tform.starttime.value > window.document.tform.endtime.va
lue)
                {    
                    window.alert("起始日期不能大于终止日期!");
                    tform.starttime.focus();
                    return false;
                }
            }
        }
        
        
        
        
        if (window.document.tform.endtime.value != "")
        {
            var vDate,vYear,vMonth,vDay;
            vDate = window.document.tform.endtime.value;
            vYear = vDate.substring(0,4);
            if (isNaN(vYear))
            {
                window.alert("您的日期2输入有误!");
                tform.endtime.focus();
                return false;
            }
            vMonth = vDate.substring(5,7);
            if (isNaN(vMonth) || vMonth < 01 || vMonth > 12)
            {
                window.alert("您的日期2输入有误!");
                tform.endtime.focus();
                return false;
            }
            vDay = vDate.substring(8,10);
            if (isNaN(vDay) || vDay == "" || vDay.length != 2 || vDay < 01 || vDay > 31)
            {
                window.alert("您的日期2输入有误!");
                tform.endtime.focus();
                return false;
            }
            
            if (vMonth == 04 || vMonth == 06 || vMonth == 09 || vMonth == 11)
            {
                if (vDay > 30)
                {
                    window.alert("您的日期2输入有误!");
                    return false;
                }
            }
            
            if (vMonth == 02)
            {
                if (vYear % 4 == 0 && vYear % 100 == 0 || vYear % 400 == 0)
                {
                    if (vDay > 29)
                    {
                        window.alert("您的日期2输入有误!");
                        tform.endtime.focus();
                        return false;
                    }
                }
                else
                {
                    if (vDay > 28)
                    {
                        window.alert("您的日期2输入有误!");
                        tform.endtime.focus();
                        return false;
                    }
                }
            }
            
            
            
            if (vDate.substring(4,5) !== "-" || vDate.substring(7,8) != "-")
            {
                window.alert("您的输入有误,请以YYYY-MM-DD格式输入!");
                tform.endtime.focus();
                return false;
            }
            
            
        }
        
        //如果必须按时间查询的话,就把注释放开就可以了
        //if (window.document.tform.starttime.value == "" && window.document.tform.end
time.value  == "")
        //{
        //    window.alert("对不起,请你输入时间!");
        //    window.document.tform.starttime.focus();
        //    return false;
        //}
        window.document.tform.action = "time.asp";
        window.document.tform.target = "time";
        window.document.tform.submit();
    }
//-->
</script>

</BODY>
</HTML>


上一篇:Javascript 实现下拉列表连动,提示:Array not define 下一篇:javascript里类似select case该如何用

版权说明:作品来源于网上,版权归作者所有,如果无意中侵犯了您的版权,请来信告知,本站将在3个工作日内删除。yesize@hotmail.com
  热门小游戏分类 
射击小游戏 连连看小游戏
台球小游戏 成人小游戏
CS小游戏 化妆小游戏
赛车小游戏 休闲小游戏
篮球小游戏 换装小游戏
儿童小游戏 牛牛小游戏
麻将小游戏 冒险小游戏
美媚小游戏 益智小游戏
体育小游戏  
Society Recreation & Sports
Travel & Leisure Communications
Vehicles Computers
Fashion Arts & Entertainment
Reference & Education Disease & Illness
Writing & Speaking Politics
Product Reviews Food & Beverage
Finance Internet Business
Self Improvement Home & Family
Health & Fitness Business
最新更新内容
警惕“公务员报考热”背
公务员考试不是丈母娘考
一名新公务员的自白:我
公务员考脑筋急转弯与挂
北努斗:2006行政能力测
大讨论:06行测BT题目大
过来人回忆:当年,我也
一家之言:公务员热折射
公务员考试申论要是有正
数十万大学生走进公务员
      粤ICP备05005424         Copyright ©2000 - 2004 Yesize.COM