如何使用 angularJS 和 jqlite 测试 event.target.hasClass()? [英] How to test if event.target.hasClass() using angularJS and jqlite?

查看:18
本文介绍了如何使用 angularJS 和 jqlite 测试 event.target.hasClass()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击后将事件传递给 ctrl.我想编写一个条件,如果 element.target 具有 modal-click-shield

类,它将返回 true

问题:

如何使用 angulars 的 jqlite.hasClass()event.target 一起使用?

问题:

目前我收到一个类型错误,提示:

$scope.exitModal = function(event){//退出模态时,通过 UI 返回当前页面.//状态返回后,应将焦点设置在匹配的链接上.var target = event.target;console.log(target.hasClass('modal-click-shield'));});

错误:

<块引用>

TypeError: undefined 不是函数

HTML:

 

解决方案

event.target 中的元素是常规 HTMLElement,而不是 JQlite 版本.你需要这样做来转换它:

angular.element(event.target);

After a click pass the event to ctrl. I want to write a conditional that will return true if the element.target has the class modal-click-shield

Question:

How can I use .hasClass() with event.target using angulars' jqlite?

Problem:

Currently I'm getting a type error saying that:

$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'));
});

Error:

TypeError: undefined is not a function

Html:

  <div class="modal-click-shield" ng-click="exitModal($event)">
     <div ui-view="pdw"  class="product-container"></div>
  </div>

解决方案

Your element from event.target is a regular HTMLElement, not the JQlite version. You need to do this to convert it:

angular.element(event.target);

这篇关于如何使用 angularJS 和 jqlite 测试 event.target.hasClass()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆