我有一個圖像,在右上角有一個垃圾桶疊加圖。我有兩個點擊事件,一個是用戶點擊垃圾「i.removeEvent」時的事件,另一個是當用戶點擊圖片「div.spaceEvent」時點擊事件,點擊時它們都會做不同的事情。但是,當用戶點擊垃圾時,它也會觸發圖像上的點擊事件。點擊垃圾箱時如何停止觸發圖像點擊?點擊疊加元素觸發點擊疊加元素
這是我的代碼。
$("div.spaceEvent").off('click').on('click', function() {
scope.eventId = $(this).data('event-id');
//$("#registeredMemberContainer").html('');
scope.GetRegisteredMembersAsHost();
});
$("i.removeEvent").off('click').on('click', function() {
scope.eventId = $(this).data('event-id');
scope.spaceId = $(this).data('space-id');
var model = {};
model.eventId = scope.eventId;
model.spaceId = scope.spaceId;
// do other stuff here
});
<ul class="thumbnails" style="padding-left: 0px;">
@{ var listItems = count > 3 ? 3 : count; } @for (int j = 0; j
< listItems; j++) { var spaceEvent=M odel.YogaSpaceEvents.ElementAt(incrament++); <li class="col-sm-4" style="padding-left: 5px; padding-right: 5px;">
<div class="spaceEvent" [email protected]>
<div class="thumbnail">
<div>
<img class="img-responsive" style="position: relative; left: 0; top: 0;" src="data:image/jpg;base64, @(Html.Raw(Convert.ToBase64String(spaceEvent.SpaceThumbnail43)))" alt="space image">
<i style="z-index: 200; position: absolute; top: 8px; right: 15px; color: whitesmoke;" class="fa fa-trash-o fa-2x removeEvent" [email protected] [email protected] data-container="body" data-toggle="popover"
data-trigger="hover" data-placement="top" data-content="Cancel event"></i>
</div>
<div class="caption" style="padding-top: 0px; padding-bottom: 0px;">
<h4 style="margin-top: 5px; margin-bottom: 5px;">@spaceEvent.Title</h4>
<p style="margin-bottom: 0px;"><span>@spaceEvent.EventDateTime.ToShortTimeString()</span><span> · </span><span>@YogaBandy2017.Models.General.EnumHelper.GetDisplayName(spaceEvent.Duration)</span></p>
<p style="margin-bottom: 0px;">@spaceEvent.StyleMain.ToString()</p>
<p class="teacher-container" style="margin-bottom: 0px;">Teacher: @(spaceEvent.IsTeacherRegistered ? spaceEvent.RegisteredTeacherName : "none")</p>
<p><span class="registered-container">Registered</span>: <span class="badge">@spaceEvent.RegisteredStudentCount/@spaceEvent.MaxSize</span></p>
</div>
</div>
</div>
</li>
count -= 1; }
</ul>
什麼stoppropagation和stopimmediatepropagation之間的區別? – user1186050
如果您已經爲事件添加了多個事件處理程序,它們將全部使用event.stopPropagation()執行,但使用event.stopImmediatePropagation()會在實際事件處理程序後停止處理。 (我會添加一個例子,給我一秒鐘) –
沒關係,我明白了! – user1186050