JAVASCRIPT中給事件處理程序傳遞參數

  1. <html>
  2. <head>
  3. <script language="javascript">
  4.  <!--
  5.    //javascript中事件傳參數的方法
  6.    function event1()
  7.    {
  8.      
  9.     }
  10.   event1.prototype={
  11.     show:function(){
  12.       this.onshow();
  13.     
  14.    }, 
  15.     onshow:function(){}
  16.    }
  17.    var object1  = new event1();
  18.    function hello(name)
  19.    {
  20.      alert("hello"+name);
  21.    }
  22. // 把有參數的涵數封裝爲無參數的涵數
  23.    function sealFunction(obj,fun)
  24.    {
  25.      if(!obj)
  26.      obj = window;
  27.      var args=[];
  28.      for(int i=2;i<arguments.length;i++){
  29.        args.push(arguments[i]);
  30.      }
  31.      return function()
  32.     {
  33.      obj[fun].apply(obj,args);
  34.     } 
  35.     }
  36.    object1.onshow=sealFunction(null,"hello","zhang");
  37.    object1.show();
  38.  -->
  39. </script>
  40. </head>
  41. <body>
  42. </body>
  43. </html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章