什么是jQuery对象? [英] What is a jQuery Object?

查看:108
本文介绍了什么是jQuery对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript种类重新定义了Array的含义,因为数组是具有.length属性和诸如.slice().join()之类的方法的对象.

JavaScript kind of redefines what an Array means because an array is an object with a .length property and methods like .slice() and .join().

jQuery将jQuery对象定义为类似于数组",因为它具有length属性,但没有像join()这样的某些数组方法.

jQuery defines a jQuery object as "Array like", because it has a length property but it doesn't have certain array methods like join().

如果我将jQuery对象定义为一个对象,而忘记提及与数组有关的任何事情,我将如何定义它呢?除了长度,它还有什么特性?

If I were to define the jQuery object as an object, and forget about mentioning anything to do with an array, how would I define it? What properties does it have besides length?

我猜所有的方法都是您在文档中看到的,远远超过了数组中方法的数量.

I guess all the methods are what you see in the documentation, far exceeding the number of methods that are in an array.

推荐答案

一个jQuery对象类似于数组,这意味着它包含零个或多个索引(名称为从零开始的正整数的属性).除了这些索引之外,jQuery对象还包含以下属性:

A jQuery object is array-like which means that it contains zero or more indexes (properties which names are positive integers starting with zero). Besides those indexes, a jQuery object contains these properties:

  • length
  • context
  • selector
  • length
  • context
  • selector

还有大约140个继承的方法(在jQuery.prototype对象上定义的方法-您可以执行console.dir(jQuery.prototype)以获得完整列表...).

And also around 140 inherited methods (which are defined on the jQuery.prototype object - you can do console.dir(jQuery.prototype) to get a full list... ).

请注意,jQuery对象不包含(或继承)Array方法(slice,substr等).如果要在jQuery对象上执行这些方法,请使用call/apply.

Note that jQuery objects do not contain (or inherit) the Array methods (slice, substr, ...). If you want to execute those methods on your jQuery object, use call/apply.

例如,如果页面上有3个TEXTAREA元素,则执行此操作:

For example, if you have 3 TEXTAREA elements on the page and you do this:

var j = $('textarea');

然后,此j jQuery对象将包含以下属性:

then this j jQuery object will contain these properties:

  • 0-引用第一个TEXTAREA元素
  • 1-引用第二个TEXTAREA元素
  • 2-引用第三个TEXTAREA元素
  • length-是3
  • context-对document对象的引用
  • selector-是'textarea'
  • 加上所有那些继承的方法...
  • 0 - reference to the first TEXTAREA element
  • 1 - reference to the second TEXTAREA element
  • 2 - reference to the third TEXTAREA element
  • length - which is 3
  • context - reference to the document object
  • selector - which is 'textarea'
  • plus all those inherited methods...

这篇关于什么是jQuery对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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