如何在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屋!
查看全文