我有以下几行:
<a href="#" id="12345" data-ng-click="ShowId()">
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有:
$scope.ShowId = function(){
alert('clicked element id in here: 12345');
};
Run Code Online (Sandbox Code Playgroud)
如何在我的控制器ShowId函数中访问被点击元素的id,在我的情况下是12345?
请注意绑定不在ng-repeat中,因此我可以访问项ID或类似的东西.
如何获取对象的id,我知道id是hola,但我需要在运行时获取它
alert($('#hola').id);
Run Code Online (Sandbox Code Playgroud)
这个想法是这样的:
<script>
(function ($) {
$.fn.hello = function(msg) {
alert('message ' + msg);
alert('is from ' + this.id); // this.id doesn't work
};
})(jQuery);
$('#hola').hello('yo');
</script>
Run Code Online (Sandbox Code Playgroud)