나는 다음 코드 구조를 수행하고 addClass item_box_popup
과 removeClass item_box
을 클릭하면 item_box div
을 수행했습니다.자녀가 부모 클릭을 클릭하는 것을 방지하는 방법
<div class="item_box"> <!--This is the small div which when clicked changes to the item_box_popup div-->
<div class="name">...</div>
<div class="detail">...</div>
</div>
<div class="item_box_popup"> <!--This div expands to show the detail and the children in it has a click event-->
<div class="name">...</div>
<div class="detail">...</div>
</div>
item_box div
에는 자식이 아닌 클릭 이벤트가 있습니다. 작업을 클릭하면 item_box_pop div
을 addClass
및 removeClass
으로 변경하는 것입니다.
item_box_popup
에는 클릭 이벤트가 없지만 하위 이벤트에 정의 된 클릭 이벤트가 있습니다. 등의 클릭 이벤트를 정의하기 위해 delegate
을 사용했습니다.
item_box div
을 클릭하면 .item_box_popup .name
에 정의 된 클릭 이벤트가 트리거되는 것이 문제입니다. 이는 .item_box
에 대한 클릭에 정의 된 변경 클래스 때문일 수 있습니다.
.item_box
클릭 할 때 클릭 이벤트가 어린이에게 표시되는 것을 원하지 않습니다. undelegate
을 시도하여 item_box 하위 항목을 클릭하는 것을 중지하고 클릭 클래스에 정의 된 변경 클래스를 수행했지만 작동하지 않습니다.
.item_box_popup
$("body").delegate('.item_box_popup .name, .item_box_popup .detail','click', function(e){
//working code here for this
});
e.stopPropagation();
에 대한 .item_box
$('.slide > div').bind('click',function(e) {
if(!$(this).hasClass('item_box_popup')){
var index=$('.slide > div').index(this);
$(this).removeClass('item_box');
$(this).addClass('item_box_popup');
Nomad.config.firstVisibleItem=index;<!--This is to set the position for .item_box_popup-->
}
});
click 이벤트에 대한 클릭 이벤트 당신은 '버블'에서 이벤트를 방지 할 필요가 .item_box
이미 시도했지만 제대로 작동하지 않습니다. – user850234
js 코드를 게시 할 수 있습니까? – FluffyKitten
@FluttyKitten 충돌하는 클릭 이벤트를 게시했습니다. – user850234