jQuery如何阻止事件冒泡

antzone發表於2017-03-02

事件冒泡現象有時候能夠起到很大的作用,有時候也會干擾操作,下面就介紹一下jQuery如何阻止事件冒泡現象。

阻止事件冒泡可以有兩種方式,列舉如下:

解決方案一:

[JavaScript] 純文字檢視 複製程式碼
$("#thediv").mousedown(function(event){ 
  event.stopPropagation(); 
  //其他程式碼
});

解決方案二:

[JavaScript] 純文字檢視 複製程式碼
$("#thediv").mousedown(function(event){ 
  return false; 
  //其他程式碼
});

相關文章