簡體   English   中英

使父 div 可點擊,但子圖標除外

[英]make a parent div clickable except for a child icon

 <div [ngClass]="{ 'template-row': ,isExpandable: 'folder-row': isExpandable }" class="label-with-icons clickable" (click)="expanderClicked()" (click)="itemSelected()" > <i *ngIf="isExpandable" [ngClass]="getArrowIconClass()"></i><i [ngClass]="getIconClass()"></i> <span *ngIf="id" class="name ">{{ name }}</span> <span *ngIf="!id" class="name">{{ name }}</span> <i *ngIf="!isExpandable" class="io-icon-trash clickable" id="delete" (click)="deleteTemplate()"></i> </div>

我希望整個 div 都是可點擊的,但不是 id=delete 的圖標。 我想有一個不同的點擊事件,我不使用 jquery,我使用 TS

您可以使用event.stopPropagation()阻止事件在 DOM 樹中向上傳播:

(click)="deleteTemplate($event)"></i>

deleteTemplate(e: Event) {
    e.stopPropagation(); // <----event won't travel up 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM