posts - 495,comments - 227,trackbacks - 0
Function.prototype.setThis=function(){
 var callFunction=this;
 var to_this_object=arguments[0];
 var pars=new Array();
 for(var i=1;i<arguments.length;i++){
  pars[i-1]=arguments[i];
 }
 return function(){
    callFunction.apply(to_this_object, pars);//如果改用call只用修改其中的参数即可。
   };
}
function test1(){
 alert(this.width);
 alert(arguments[0]);
 alert(arguments[1]);
}

function addOnclick(elObj){
   elObj.onclick=test1.setThis(img,"tttttt");
}

这样在触发onclick事件时,可以传递参数。
posted on 2006-12-27 11:41 SIMONE 阅读(1551) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航: