庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>WEB开发>JavaScript>应用技巧>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

利用JavaScript实现时间段的查询

 作者:本站收集   日期:2005-3-16
字号选择〖 〗/ 双击滚屏 单击停止   


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

希望大家能帮我测试一下,输入的时间格式是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 defined    下一篇:javascript里类似select case该如何用  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-3-16
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿