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

Javascript
JavaScript窗口功能指南之检查一个窗口是否存在
用JAVASCIRPT写的一个动态显示日期的函数!
JavaScript窗口功能指南之打开一个新窗口
JavaScript窗口功能指南之在窗口中书写内容
JavaScript窗口功能指南之引用已打开的窗口
JavaScript窗口功能指南之发挥窗口特征
JavaScript窗口功能指南之命名窗口和框架
JavaScript窗口功能指南之创建对话框
对连串英文自动换行的解决方法 IE5.5 无忧脚本
javascript扫雷游戏,版本二
window.external的使用
JavaScript 是什麽?
SelectBox in Frame
24点终结者(javascript)
用Javascript转换源代码
JS特效之状态栏冒泡
JavaScript:实现滚动带链接的字幕
jscript错误代码及相应解释大全
实现随鼠标飘浮移动文字的JavaScript
怎样捕捉 Delete 键

JS学习笔记:Javascript类的继承


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 49 ::
收藏到网摘: 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" >