我有一個選擇器綁定一個點擊事件,將刪除彈出。不過,我只希望選擇器能夠處理點擊,而不是選擇器的子元素能夠觸發點擊事件。防止點擊孩子發射父母點擊事件
我的代碼:
<div id="popup">
<div class="popup-content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
當.popup-content
點擊,這將觸發click事件時,我不希望的#popup
的孩子這樣做。
jQuery代碼:
$('#popup').bind('click', function()
{
$(this).remove();
});
可能重複(http://stackoverflow.com/questions/2244320/jquery-click-event-propagation) –