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 閱讀(1561)
評論(0) 編輯 收藏 所屬分類:
JavaScript