易截截图软件、单文件、免安装、纯绿色、仅160KB

Javascript检查日期格式是否合法的一种简化方法。

常规的方法是将年月日取出,然后分别判断范围,然后就判断闰年2月的天数
可以通过new Date(string)的构造,比较年月日字符是否发生变化判断。
function CheckDate(text) {
if (!text) return false;
text = text.replace(/[\/-]0?/g, "/");
if (!text.match(/^\d{4}\/\d{1,2}\/\d{1,2}$/)) return true;
var d = new Date(text);
return [d.getFullYear(), d.getMonth() + 1, d.getDate()].join("/") != text;
}
document.open();
var datas = ["", "2010-01-01", "2010/02/30", "2010/02", "2010/22/30", "2012/2/29", "2012/02/29"];
for(var i = 0; i < datas.length; i++) {
document.write(datas[i], "=", CheckDate(datas[i]), "<br/>");
}
document.close();

输出:
=false
2010-01-01=false
2010/02/30=true
2010/02=true
2010/22/30=true
2012/2/29=false
2012/02/29=false


相关文档:

Javascript陷阱。。。。。。。

1.浮点运算
这可能是挫败一些对javascript不熟悉并准备执行一些数学运算的人的主要原
因.
<script>  
alert(0.02 / 0.1);  //0.19999999999999998 
  
alert(1.14 * 100);  //113.99999999999999    ;)
  
......

[翻译]High Performance JavaScript(009)

第三章  DOM Scripting  DOM编程
    DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations o ......

自己写的javascript五子棋

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>five-in-a-raw</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <style>
  ......

Javascript闭包(Closure)

Closure中文翻译为闭包.字面上来理解就是"封闭的包".(这是一句废话)
闭包是什么?
书面解释为:
所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。
我认为闭包就是能够读/写函数内部的某些变量的子函数,并将这些变量保存 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号