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

JavaScript编程笔记

新中……
1、数据类型验证问题
  Asp.Net虽然有验证控件,但是有些复杂的验证还是得传到服务器上进行,用js速度和性能都比较好
<script>
 //检查是否为任意数(实数)
function isNumeric(strNumber) {
var newPar=/^(-|\+)?\d+(\.\d+)?$/
alert(newPar.test(strNumber)); }
 //检查是否为正数
function isUnsignedNumeric(strNumber) {
var newPar=/^\d+(\.\d+)?$/
alert(newPar.test(strNumber)); }
//检查是否为整数
function isInteger(strInteger) {
var newPar=/^(-|\+)?\d+$/
alert(newPar.test(strInteger)); }
//检查是否为正整数
function isUnsignedInteger(strInteger) {
var newPar=/^\d+$/
alert(newPar.test(strInteger)); }
</script>
2、asp.net中用alert()实现换行问题
     asp.net中用response.Write("<script>alert('提示:\n操作出错!');</script>");无法执行。
     将字符串写成
     say="提示:\\n操作出错!"
     say=@"提示:\n操作出错!"
  
 3、js实现刷新验证码
     单击图片刷新:
<img id="CheckImg" src="CreatImage.aspx" onclick="this.src='CreatImage.aspx?temp='+Math.random()"/>
     单击“刷新验证码”按钮刷新
    function imagechick()
   {
     form1.CheckImg.src="CreatImage.aspx?temp="+Math.random();
     return false;//不上传到服务器
   }
     其中CreatImage.aspx为产生验证码图片的页面,源码见:C#产生图形验证码
4、js中使用正则表达式的方法
    格式是:/正则表达式/
    必须用两个斜杠把正则表达式括起来。
   如非法字符检测正则表达式为:^(?:[\u4e00-\u9fa5]*\w*\s*)+$
   使用的代码为:
      var newPar=/^(?:[\u4e00-\u9fa5]*\w*\s*)+$/;
      if(newPar.test("1234&1238*_~"))
      {
         &


相关文档:

[翻译]High Performance JavaScript(013)

Conditionals  条件表达式
    Similar in nature to loops, conditionals determine how execution flows through JavaScript. The traditional argument of whether to use if-else statements or a switch statement applies to JavaScript just as it does to other languages. Since different b ......

[翻译]High Performance JavaScript(014)

Recursion Patterns  递归模式
    When you run into a call stack size limit, your first step should be to identify any instances of recursion in the code. To that end, there are two recursive patterns to be aware of. The first is the straightforward recursive pattern represented ......

[翻译]High Performance JavaScript(025)

第八章  Programming Practices  编程实践
    Every programming language has pain points and inefficient patterns that develop over time. The appearance of these traits occurs as people migrate to the language and start pushing its boundaries. Since 2005, when the term "Ajax" ......

用JavaScript写的小时候玩的乒乓球小游戏

由于火狐浏览器不支持“removeNode”函数,所以一下代码只支持IE.
<!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>
< ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号