动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   JavaScript → 阅读文章

 利用JavaScript实现时间段的查询

作者来源: 
阅读 数 631 人次 , 2006-3-29 3:48:00 


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

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

 本文Tags组网  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:javascript里类似select case该如何用
· 下一篇:Javascript 实现下拉列表连动,提示:Array not defined
· JavaScript 模拟游戏中的弹出菜单效果
· JavaScript[对象.属性]集锦之一
· 一个通用验证javascript函数
· JavaScript 对象的基本知识
· 一个javascript脚本写的俄罗斯方块


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077