DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JS學習筆記:Javascript類的繼承
JS學習筆記:Javascript類的繼承
編輯:關於JavaScript     

網頁制作poluoluo文章簡介:JavaScript中類的學習,從基本類繼承過來方法。

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" >  

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved