阻止默认事件和冒泡
阻止默認事件
html標簽會有一些默認事件,比如a標簽跳轉,button標簽提交表單,有時我們需要控制這些操作,阻止它的默認事件
1.return false;
$("a").click(function(){//一些我們需要的操作 console.log(balala……)return false; //最后return false會阻止跳轉 })?
?
2.e.preventDefault;
$("a").click(function(e){e.preventDefault();//一些我們需要的操作 console.log(balala……); })?
?
阻止事件冒泡
點擊子元素時,會觸發父元素的事件,一級級往上出發,我們用cancelBubble和stopPropagation來阻止事件的冒泡
function doSomething (evt) {var e=(evt)?evt:window.event; if (window.event) { e.cancelBubble=true;} else { e.stopPropagation();} }?
轉載于:https://www.cnblogs.com/jidi/p/prevent.html
總結
- 上一篇: Linux 中 SVN 重启关闭
- 下一篇: DevExpress TreeListL