- <html>
- <head>
- <script language="javascript">
- <!--
- //javascript中事件傳參數的方法
- function event1()
- {
- }
- event1.prototype={
- show:function(){
- this.onshow();
- },
- onshow:function(){}
- }
- var object1 = new event1();
- function hello(name)
- {
- alert("hello"+name);
- }
- // 把有參數的涵數封裝爲無參數的涵數
- function sealFunction(obj,fun)
- {
- if(!obj)
- obj = window;
- var args=[];
- for(int i=2;i<arguments.length;i++){
- args.push(arguments[i]);
- }
- return function()
- {
- obj[fun].apply(obj,args);
- }
- }
- object1.onshow=sealFunction(null,"hello","zhang");
- object1.show();
- -->
- </script>
- </head>
- <body>
- </body>
- </html>
JAVASCRIPT中給事件處理程序傳遞參數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.