js监听

IE浏览器监听:

    function attachEvent(string eventFlag, function eventFunc)
    eventFlag: 事件名称,但要加上on,如onclick、onmouseover…
    eventFunc: 绑定到事件中执行的动作
    在事件监听流中可以使用window.event.cacenlBubble=false来阻止事件继续往下流

非IE浏览器监听:

    function addEventListener(string eventFlag, function eventFunc, [bool useCapture=false])
    eventFlag : 事件名称,如click、mouseover…
    eventFunc: 绑定到事件中执行的动作
    useCapture: 指定是否绑定在捕获阶段,true为是捕获阶段,false为冒泡阶段,默认为true
    在事件监听流中可以使用event.stopPropagation()来阻止事件继续往下流

防止冒泡:

    var stopEvent = function(event){ e = event || window.event; if(e.stopPropagation){ e.stopPropagation(); }else { e.cancelBubble = true; } };

 

posted @ 2016-03-18 10:32  走向未知  阅读(620)  评论(0编辑  收藏  举报