2015-03-19 39 views
1

0123xx元素上的ng-click指令的事件即使通過它的同級元素input正在註冊。ng-click事件偵聽器在單擊同級元素時觸發

<div class="list list-inset"> 
 
    <label class="item item-input"> 
 
    <button class="button button-small button-icon icon ion-navicon" 
 
      ng-click="toggleLeft();$event.stopPropagation();"></button> 
 
    <input type="text" placeholder="Search"> 
 
    </label> 
 
</div>

點擊input元素也在裏面的任何地方內觸發點擊事件。 我該如何解決這個問題?

+0

我沒有看到這種行爲。也許你需要進一步指定你的問題(提供一個詳細的例子,包括額外的樣式) – Rouby 2015-03-19 07:19:06

+0

@Rouby問題發生是因爲標籤內部的元素。 – 2015-03-19 07:28:48

+0

@Rouby它是一樣的。標記爲重複。 – 2015-03-19 12:50:21

回答

1

將事件偵聽器添加到<label>中包含的元素將在該容器內的任何位置觸發事件。

angularjs ng-click event of two sibling tag fired, instead of one

<div class="list list-inset"> 
 
    <div class="item item-input"> 
 
    <button class="button button-small button-icon icon ion-navicon" 
 
      ng-click="toggleLeft()"></button> 
 
    <input type="text" placeholder="Search"> 
 
    </div> 
 
</div>

相關問題