什么是默认行为?
var a = document.getElementById(‘a‘); a.addEventListener(‘click‘,function(e){ e.preventDefault(); },false);
兼容性问题:
function preventDefault(event){ var event = $$.getEvent(event); if(event.preventDefault){ event.preventDefault(); }else{ event.returnValue = false; //微软 } }
什么是阻止冒泡
$$(‘div2‘).addEventListener(‘click‘,function(event){ event.stopPropagation(); },false)
兼容性问题
function stopPropagation(event){ var event = $$.getEvent(event); if(event.stopPropagation){ event.stopPropagation(); }else{ event.cancelBubble = true; } }
时间: 2024-10-27 06:08:32