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

Javascript
document.createElement()用法及注意事项
Javascript教程:关于内存泄漏问题
延迟事件为0的setTimeout的真正目的
JavaScript图片特效代码下载
AJAX初学:IE缓存页面的问题
AJAX中DOM的操作方法
AJAX中文乱码的两类问题
javascript程序的执行效率问题
网页用户注册界面的设计
ajax应该如何应用?
详解Javascript匿名函数的使用
Ajax:研究密码强度规则(仿google)
JavaScript学习教程
网页制作中常用的Javascript代码
深入学习Javascript函数
JS的Object类的属性和方法
Javascript初学者实例教程(1):简单交互
Javascript初学者实例教程(2):event对象和事件
Javascript初学者实例教程(3):数组和slice()方法
Javascript初学者实例教程(4):对象和构造方法

JS学习笔记:Javascript类的继承


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