如何同时传event以及其他参数

来源:互联网 发布:淘宝网电视机 编辑:程序博客网 时间:2024/05/19 22:04

有时方法需要同时传递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

阅读全文
0 0
原创粉丝点击