Mat*_*ood 5 javascript javascript-events angularjs angularjs-ng-click jqlite
单击后将事件传递给ctrl.我想编写一个条件,如果element.target有类,它将返回truemodal-click-shield
题:
如何使用.hasClass()与event.target利用angulars' jqlite?
问题:
目前我收到类型错误说:
$scope.exitModal = function(event){
// Return to current page when exiting the modal, via UI.
// After state return, should set focus on the matching link.
var target = event.target;
console.log(target.hasClass('modal-click-shield'));
});
Run Code Online (Sandbox Code Playgroud)
错误:
TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="modal-click-shield" ng-click="exitModal($event)">
<div ui-view="pdw" class="product-container"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
ris*_*sto 17
您的元素来自event.target常规HTMLElement,而不是JQlite版本.你需要这样做才能转换它:
angular.element(event.target);
Run Code Online (Sandbox Code Playgroud)
如果你想在不使用jQuery或angular的情况下继续使用你的JS DOM元素:
event.target.classList.contains('modal-click-shield')
Run Code Online (Sandbox Code Playgroud)