当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS学习笔记:Javascript类的继承

Javascript
动态生成select选项全接触
不刷新页面动态更新select选项,实现两个select相互操作
网页输入框日期型有效性判定一网打尽
实用Javascript函数之一(自动将输入文本框中的内容转换成大写字符)
实用Javascript函数之二(自动将输入文本框中的内容转换成小写字符)
实用Javascript函数之三(限制文本输入框中只能输入数字\"0\"到\"9\")
实用Javascript函数之四(用于对sString字符串进行前空格截除)
实用Javascript函数之五(用于对sString字符串进行后空格截除)
实用Javascript函数之六(截除字符串前后空格)
如何使用交替的滚动标题
采用DOM模型时创建一个Select节点后,要删除option项的解决方法
javascript函数速查
利用JavaScript和正则表达式进行丰富的日期判断(给其它项目组的代码,有比较好的编程风格和注释)
关于字符串的几个有用函数
FileSystemObject 的例子(处理驱动器、文件夹、文件)
用JScript实现VB.Net,C#的[委托Delegate]:
得到固定字符位置的函数
IE NC通用的藏鼠标右键一法
Menu
foolpot2001菜单

JS学习笔记:Javascript类的继承


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 58 ::
收藏到网摘: n/a

JavaScript中类的学习,从基本类继承过来方法

也可以这样实现:

Java代码

function newClass(){   
     this.firstName="frank";   
     this.toUc=String.toUpperCase;   
     this.toString=function(){   
        return this.toUc(this.firstName);   
     }   
 }   
 var nc=new newClass();   
 alert(nc);//在IE中没反应。。  
   function newClass(){
        this.firstName="frank";
        this.toUc=String.toUpperCase;
        this.toString=function(){
           return this.toUc(this.firstName);
        }
    }
    var nc=new newClass();
    alert(nc);//在IE中没反应。。

一个简单的客户端验证

Java代码

<html>   
<head>   
  <title>javascript</title>   
    <script type="text/javascript">   
        function doSubmit(inForm){   
            if(inForm.firstName.value==""){   
                alert("firstName is null");   
                return false;   
            }   
            if(inForm.lastName.value ==""){   
                alert("lastName is null");   
            }   
            inForm.submit();   
            return true;   
        }   
    </script>   
</head>   
<body>   
<form action="#" name="test" method="post">   
    First name: <input type="text" name="firstName">   
    <br>   
    Last name:<input type="text" name="lastName">   
    <br>   
    <input type="button" value="submit" onclick="doSubmit(this.form);">   
</form>   
</body>   
</html>   
</form>  
<html>
<head>
  <title>javascript</title>
    <script type="text/javascript">
        function doSubmit(inForm){
            if(inForm.firstName.value==""){
                alert("firstName is null");
                return false;
            }
            if(inForm.lastName.value ==""){
                alert("lastName is null");
            }
            inForm.submit();
            return true;
        }
    </script>
</head>
<body>
<form action="#" name="test" method="post">
    First name: <input type="text" name="firstName">
    <br>
    Last name:<input type="text" name="lastName">
    <br>
    <input type="button" value="submit" onclick="doSubmit(this.form);">
</form>
</body>
</html>
</form>

一般这样写

Java代码

<form action="#" name="test" method="post" onSubmit="return doSubmit(this);">   
    First name: <input type="text" name="firstName">   
    <br>   
    Last name:<input type="text" name="lastName">   
    <br>   
    <input type="button" value="submit" >