javascript AngularJS ng-单击表格行而不是某个td
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23890150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AngularJS ng-click on table row but not on a certain td
提问by Liad Livnat
I'm facing an issue when there is an event data-ng-click on table row, but i want that a certain td won't do the event in the row.
当表行上有一个事件 data-ng-click 时,我面临一个问题,但我希望某个 td 不会在行中执行该事件。
is it possible to do it?
有可能做到吗?
if so, how?
如果是这样,如何?
example html:
示例 html:
<table>
<tr data-ng-click="do_some_action()">
<td>
cell 1 is clickable
</td>
<td>
cell 2 is clickable
</td>
<td class="not-clickable-cell">
cell 3 is not! clickable
</td>
</tr>
</table>
回答by dfsq
You can stop event propagation like this:
您可以像这样停止事件传播:
<td class="not-clickable-cell" ng-click="$event.stopPropagation()">
cell 3 is not! clickable
</td>
so that when you click this cell event will not bubble up to the tr
event handler.
这样当您单击此单元格事件时,事件不会冒泡到tr
事件处理程序。
Demo: http://plnkr.co/edit/jvh5NKaDsvpPKuSJhzFx?p=preview
演示:http: //plnkr.co/edit/jvh5NKaDsvpPKuSJhzFx?p=preview
回答by TheLawrence
You could write something in the do_some_action function that explicitly makes it ignore the class "not-clickable-call". It would be a easier to say with a jsfiddle or example of what that function is.
您可以在 do_some_action 函数中编写一些内容,明确使其忽略类“not-clickable-call”。使用 jsfiddle 或该函数是什么的示例会更容易说出来。