jQuery - 访问each()函数中的所有元素

Ale*_*lex 0 javascript jquery jquery-plugins

我有一个jquery函数,它挂在所有输入元素上,如:

$("input").blah();

如何从此函数中访问此类型的所有元素?不只是当前由jQuery处理的那个.

该功能如下:

(function($) {
  $.fn.blah = function(){

     this.each(function(){

       // how can I access all elements of type "this" here?

       return this;
     });

 };

})(jQuery);
Run Code Online (Sandbox Code Playgroud)

我想从所有这些元素中读取一些属性,然后根据这些属性对正在处理的当前元素执行一些操作

Ray*_*nos 6

(function($) {
  $.fn.blah = function(){

     var that = this;
     this.each(function(index, element){

       // this here means the element in that[i]
       // that here means the original jQuery object.

       return this;
     });

 };

})(jQuery);
Run Code Online (Sandbox Code Playgroud)

您可以保存this在变量中,然后在.each回调中进行访问.