I'm trying to send a div's id into a function as a parameter when clicked.
But it is not working.
Here's what I have written, please take a look :
<div id="currentId" ng-click="functionCalled(id)">
</div>
Edit your code with,
HTML:
<button id="bla" class="button button-light" data-ng-click="functionCalled($event)">
Click Me
</button>
JS:
$scope.functionCalled= function(event){
alert(event.target.id);
}
尝试对此对象使用以下方法<div id="currentId" ng-click="functionCalled(this.id)"> </div>
The click event function has the event as an argument.
<div id="currentId" ng-click="functionCalled(event)">
Now you can access the properties from the target property in the in the event argument.
function functionCalled(event){
let id = event.target.id;
}
<div id="currentId" ng-click="functionCalled($event)">
</div>
In your controller
functionCalled($event){
//use $event.target.id
}
you can pass this as $event
<div id="currentId" ng-click="functionCalled($event)"></div>
and use this as
e.target.attributes.id.value
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.