如何在angularjs中检索单击的ElementId? [英] How to retrieve the clicked ElementId in angularjs?
本文介绍了如何在angularjs中检索单击的ElementId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下一行:
<a href="#" id="12345" data-ng-click="ShowId()">
在我的控制器中,我有:
and in my controller I have:
$scope.ShowId = function(){
alert('clicked element id in here: 12345');
};
如何在我的控制器ShowId函数中访问被单击元素的ID(在我的情况下为12345)?
How can I access in my controller ShowId function the id of the clicked element, in my case 12345?
请注意,绑定不在ng-repeat内,因此我可以访问项目ID或类似内容.
Notice the bind is not within the ng-repeat so I can access the item id or something like that.
推荐答案
我解决了这个问题:
<a href="#" id="12345" data-ng-click="ShowId($event)">
$scope.ShowId = function(event)
{
alert(event.target.id);
};
这篇关于如何在angularjs中检索单击的ElementId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文