事件冒泡(点击穿透)

window.onload = function () {

            var oDiv1 = document.getElementById('div1');//子

            var oDiv2 = document.getElementById('div2');//父

            oDiv1.onclick = function (ev){

                var oEvent = ev || event;

                alert("this is div1");


                //js阻止事件冒泡

                oEvent.cancelBubble = true;

                oEvent.stopPropagation();

                //js阻止链接默认行为,没有停止冒泡

                //oEvent.preventDefault();

                //return false;

            }

            oDiv2.onclick = function (ev){

                var oEvent = ev || event;

                alert("this is div2");

                oEvent.cancelBubble = true;

            }

        }

你可能感兴趣的:(事件冒泡(点击穿透))