首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

if (e.stopPropagation) {e.stopPropagation();}解决方法

2013-09-05 
if (e.stopPropagation) {e.stopPropagation()}问题1:function doSubmit(e),里边为什么加个 e,表达什么含

if (e.stopPropagation) {e.stopPropagation();}
问题1:function doSubmit(e),里边为什么加个 e,表达什么含义

问题2:if (e.stopPropagation) {e.stopPropagation();}      e.stopPropagation出现2次,什么意思

问题3:我百度下,下边2个都是阻止事件的扩散,为什么这么做?
    if (e.stopPropagation) {e.stopPropagation();}     
    e.cancelBubble = true;   





function doSubmit(e) {
    if (formChecker != null) {
        clearInterval(formChecker);
        formChecker = null;}                           //清除定时器
    e = e || window.event;
    if (e.stopPropagation) {e.stopPropagation();}
    e.cancelBubble = true;
    try {
        $("input[type='submit']").attr("disabled", "disabled");
        swfu.startUpload();                             //上传队列中第一个文件
    } catch (ex) {
        $("input[type='submit']").removeAttr("disabled");
        this.debug(ex);
    }
    return false;
}

[解决办法]
1、e是事件触发后传进来的一堆参数,可以自己打印一下看看。
2、判断是否有效,IE貌似不支持。
3、cancelBubble是ie以及版本较新的chrome opera组织事件冒泡的,firefox不支持,所以就要用stopPropagation来兼容ff。


所以2、3就是为了兼容性,
[解决办法]
1、表示事件对象
2、先判断是否存在,再执行,很合乎常理啊
3、兼容浏览器,首先尝试使用DOM方法阻止事件流,否则就使用 IE 的 cancelBubble  属性。
[解决办法]
可以这么理解
stopPropagation 是e 的方法或属性

热点排行