欢迎光临
我们一直在努力

利用JAVASCRIPT实现时间段的查询

建站超值云服务器,限时71元/月

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

希望大家能帮我测试一下,输入的时间格式是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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用JAVASCRIPT实现时间段的查询
分享到: 更多 (0)

相关推荐

  • 暂无文章