Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery AngularJS指令中的元素与此_Jquery_Angularjs_Angularjs Directive - Fatal编程技术网

Jquery AngularJS指令中的元素与此

Jquery AngularJS指令中的元素与此,jquery,angularjs,angularjs-directive,Jquery,Angularjs,Angularjs Directive,一旦jQuery包含在Angular、inside指令中,就可以自由地使用$(element)和$(this)进行DOM操作 他们之间有什么区别?一个比另一个好吗?它们是可互换的吗?由于angular js使用jqlite(jquery的一个最小版本)作为选择器,因此angular js中的选择器可能相同,但名称也不同 参考: 由于angular js使用jqlite(jquery的最低版本)作为选择器,因此angular js中的选择器可能相同,但名称不同 参考: $(此)将取决于正在执行的方

一旦jQuery包含在Angular、inside指令中,就可以自由地使用$(element)和$(this)进行DOM操作


他们之间有什么区别?一个比另一个好吗?它们是可互换的吗?

由于angular js使用jqlite(jquery的一个最小版本)作为选择器,因此angular js中的选择器可能相同,但名称也不同

参考:

由于angular js使用jqlite(jquery的最低版本)作为选择器,因此angular js中的选择器可能相同,但名称不同

参考:
$(此)
将取决于正在执行的方法的上下文,
$(元素)
将始终引用该指令所附加的

这里有一个人为的例子

module.directive('myDirective', [function() {
    return {
        template: '<div><button id="btn">Click Me</button></div>',
        restrict: 'E',
        link: function(scope, element, attrs, controller) {
                $("#btn").on('click', function() {
                    // $(this) != $(element)
                    // $(this) is the button element from the template
                    // $(element) is the directive element
                });
            }
        }
}]);
module.directive('myDirective',[function(){
返回{
模板:“单击我”,
限制:'E',
链接:功能(范围、元素、属性、控制器){
$(“#btn”)。在('click',function()上{
//$(此)!=$(元素)
//$(这)是模板中的按钮元素
//$(元素)是指令元素
});
}
}
}]);
$(此)
将取决于正在执行的方法的上下文,
$(元素)
将始终引用该指令所附加的

这里有一个人为的例子

module.directive('myDirective', [function() {
    return {
        template: '<div><button id="btn">Click Me</button></div>',
        restrict: 'E',
        link: function(scope, element, attrs, controller) {
                $("#btn").on('click', function() {
                    // $(this) != $(element)
                    // $(this) is the button element from the template
                    // $(element) is the directive element
                });
            }
        }
}]);
module.directive('myDirective',[function(){
返回{
模板:“单击我”,
限制:'E',
链接:功能(范围、元素、属性、控制器){
$(“#btn”)。在('click',function()上{
//$(此)!=$(元素)
//$(这)是模板中的按钮元素
//$(元素)是指令元素
});
}
}
}]);

Intersting answer了解JavaScript中此关键字的更多信息:Intersting answer了解JavaScript中此关键字的更多信息: