JavaScript最简略比较两个时间格式数据的大小
呵呵呵,在软件研发过程中如果遇到要比较两个时间的大小,你会怎么做,嗯嗯嗯,很直观的做法就是把“-”去掉,再比较大小,真的有必要吗?看下面最简单的时间比较方式:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JavaScript最简单比较两个时间格式数据的大小</title>
<script type="text/javascript" src="./jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function checkDate(){
if($("#startDate").val() > $("#endDate").val()) {
alert("结束时间必须大于等于开始时间!");
}
}
</script>
</head>
<body>
开始时间:<input id="startDate" value="2013-12-31"/><br>
结束时间:<input id="endDate" value="2013-01-01"/><br>
<input type="button" onclick = "checkDate();" value="开始比较"/>
</body>
</html>
【0分下载资源】