我是靠谱客的博主 无辜秀发,这篇文章主要介绍如何同时传event以及其他参数,现在分享给大家,希望可以做个参考。

有时方法需要同时传递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以及其他参数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(115)

评论列表共有 0 条评论

立即
投稿
返回
顶部