棱角分明如何防止点击事件传播到日期选取器元素

Angular-strap how to prevent click event propagation to datepicker element

本文关键字:传播 日期 选取 元素 事件 何防止      更新时间:2023-09-26

我使用角度带库来添加日期选择器元素。输入元素在一行中,当我单击行时,我会更改它的颜色。现在,当我使用类日期选择器或其他子表行单击div时,将触发该事件。我需要阻止它。我该怎么办?

    <table class='css_table'>
        <thead class='css_thead'>
            <tr class='css_tr'>
                <th class='css_th'>Data</th>
            </tr>
        </thead>
        <tbody class='css_tbody' ng-repeat='home in village'>
            <tr ng-click='select(home)' ng-class="{'selected':home.isSelected}" >
                <td class='css_td'>
                    <input type="text" ng-model="selectedDate" name="date" ng-click='$event.stopPropagation()' bs-datepicker>
                </td>
            </tr>
    </tbody>
</table>

$scope.select = function(home){
    
    if(home.isSelected == undefined){
        home.isSelected = true;
    }else{
        home.isSelected = !home.isSelected;
    }
}

这段代码应该可以工作。

<div ng-click="parentHandler()">
    <div ng-click="childHandler(); $event.stopPropagation()"></div>
</div>