面向对象的 javascript的几个最重要的特性的讲解和实例以及全套javascript的例子.doc

OOP JavaScript

1.DISPLAY TIME IN FLY

(1)   real object

(2)   c style

(3)   animation usage

 

<html>

   <head>

      <title>DISPLAY TIME IN FLY</title>

      <script language="javascript">

        function display_time(){

           var date = new Date();

           document.form_1.time_display.value = date.getHours() + "  " + date.getMinutes() + "  " + date.getSeconds();

           self.setTimeout("display_time()", 2000);  //2000ms

        }     

     

      </script>     

   </head>

   <body>

      <p>DISPLAY TIME IN FLY</p>

     <form  name="form_1">

        <input type="text"  name="time_display" />

        <script language="javascript">

           display_time();

        </script>

     </form>

   </body>

</html>

 

 

 

 

 

2.String Object and Regular expression

 

<html>

   <head>

      <title>test regular expression</title>

   </head>

   <body>

      <p>TEST REGULAR EXPRESSION</p>

      <script language="JavaScript">

       var regex_number = //d+/g;

       var test = "9981723";

       if( test.match(regex_number) ) {

          alert("matched, hehe");

       } 

      </script>     

   </body>

</html>

 

 

 

3.CSS and JavaScript(我实际上是想提供一个css的快速入门例子)

 

 

 

<html>

   <head>

      <title>CSS and used in JavaScript</title>

      <style type="text/css" >

       H1 {color:red; } 

       H2 {color:blue; font-style:italic;}

       H2.ALLCAPS {text-transform: uppercase;}

       .RED_COLOR {color:red; }

      </style>     

   </head>

   <body>

      <p>CSS and used in JavaScript</p>

     <h1>this is 1st level head</h1>     

    <script language="JavaScript">

         document.write("<h2 class='RED_COLOR'>that is 2nd level head</h2>");

         document.write("<h2 class='ALLCAPS'>we need upper cases</h2>");

    </script>

     <h3>my 3rd level head</h3>

   </body>

</html>

 

 

 

 

 

4.javascript中使用perl style array, perl style hash, loop, function

 

<html>

   <head>

      <title>array like perl, function as data, unix script style for loop, varied argument length</title>

   </head>

   <body>

      <p>array like perl, hash like perl,function as data, unix script style for loop, varied argument length</p>

     <script language="JavaScript">

        var a=[-1,-1,1,-3,-3];

       function f(s,e)

       {

         var ret=[];

         for(var index=0; index<a.length; index++){

             alert ("test array " + a[index] );

            ret.push(a[index]);

         }

       }

       var b= f(a);

      

       var h = { "leo":"baba",  "lele":"erzi" };     

       alert ("test hash " +  h["leo"]   );

      

       // print all keys and values in hash

       for (var i in h){

          alert (i +"  " +  h[i]);

       }      

 

     </script>     

   </body>

</html>

 

 

 

 

5.完整的对象例子( 构造函数, property, method, 使用对象)

 

<html>

   <head>

      <title>perl style object</title>

   </head>

   <body>

      <p>perl style object</p>

      <script language="javascript">

     

      //function style object

      function OEmploy(employ_id){

 

        //(1) construction fuction

         this.id = employ_id;

       

        if( arguments.length == 2 ){

           this.name = arguments[1];

        }        

 

        if( arguments.length == 3 ){

           this.name = arguments[1];

           this.address = arguments[2];

       }        

      

        if( arguments.length == 4 ){

           this.name = arguments[1];

           this.address = arguments[2];

           this.telephone_number = arguments[3];

        }        

      

       //(2)  method enclosed in object

        this.method_1 = function () {

            alert ("this is the name of " + this.name  );

        }      

      

        this.method_2 = function () {

            this.method_1();

        }      

 

     }     

    

 

     //(3) utilize the object

     var  emp_1 = new OEmploy(112,"leo");

     emp_1.method_1();

 

      </script>

   </body>

</html>

 

 

 

 

 

 

 

对于绝大多数程序员来讲,还是用javascript在客户端browser进行编程,

主要还是使用host object( window, document), 本文第二部分将举一个和JDOM结合的例子详细讲解在Browser( IE, Firefox)上进行 OOP 例子, 并且列出比较常用的html, javascriptspecification website 和常见 example的网站.

 

附件中的javascript例子很全,是我从

<< Javascript王者归来>>copy下来的.

 

 

 

Log4j.js是一个完整的oop javascript例子

 

 

csdn blog上面不能有文件,我直接将这两个实用的附件上传到资源中心吧.

大家可以用 "site:csdn.net 面向对象的javascript log4j.js"baidu中进行search

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值