有时方法需要同时传递event防止冒泡和其他参数,因此可以将方法进行封装。
function x(e,str){
var a=e||window.event;
if(a.stopPropagation){
a.stopPropagation();
}else{
a.cancelBubble=true;
}
alert(str);
}
window.onload=function(){
document.getElementById('span').onclick=function(e){
x(e,'mm');
}
}
或者一种更简单的
function x(e){
var a=e||window.event;
if(a.stopPropagation){
a.stopPropagation();
}else{
a.cancelBubble=true;
}
}
window.onload=function(){
document.getElementById('span').onclick=function(e,str){
x(e);
alert(str);
}
}
欢迎访问个人博客:cheeseyu.cn
最后
以上就是无辜秀发最近收集整理的关于如何同时传event以及其他参数的全部内容,更多相关如何同时传event以及其他参数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复