当前位置: 移动技术网 > IT编程>开发语言>JavaScript > angularJs中怎么模拟jQuery中的this?(转)

angularJs中怎么模拟jQuery中的this?(转)

2018年02月24日  | 移动技术网IT编程  | 我要评论

转载自mini_fan博客园:

今天想在Angular项目中使用jQuery的this功能,发现undefined。代码如下:

HTML部分:

 <p ng-click="testClick()">testClick1</p>

Js部分:

$scope.testClick=function () {
     console.log($(this).html());
 }

提示信息:ReferenceError $ is not defined

问题分析:

在angularJs中,this指向$scope!可以$event配合使用$(event.target)实现,代码如下:

HTML部分:

<p ng-click="testClick($event)">testClick1</p>

Js部分:

$scope.testClick=function (event) {
    console.log($(event.target).html());
}

解决,我刚好也遇到这个问题,可是angular.js用jQuery特效,总有不尽入人意,还是补习补习js,jquery,html,css的基础知识.

 

原文地址:https://www.cnblogs.com/mini-fan/p/6555836.html

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网