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

javascript 遏止事件元素默认行为和传播(冒泡)

2012-09-05 
javascript 阻止事件元素默认行为和传播(冒泡)document.getElementById(id).onclick function(e){e

javascript 阻止事件元素默认行为和传播(冒泡)

document.getElementById('id').onclick = function(e){e = e || window.event;var target = e.target || e.srcElement;// do something//prevent default actionif(typeof e.preventDefault === 'function'){e.preventDefault();e.stopPropagation();}else{e.returnValue = false;e.cancelBubble = true;}}

热点排行