jQuery $实际返回什么? [英] What does jquery $ actually return?

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

问题描述

我已经阅读了JQuery文档,尽管对您应该通过传递的功能投入了很多注意力,但是我没有看到有关它实际返回的内容的任何信息

I have read the JQuery documentation, and while much attention is devoted to what you should pass the function, I don't see any information on what it actually returns.

特别是,即使仅找到一个元素,它也总是返回一个数组吗?当什么都没找到时,它返回null吗?在哪里记录?

In particular, does it always return an array, even if only one element is found? Does it return null when nothing is found? Where is this documented?

我知道可以将jquery方法应用于返回值,但是如果我想直接使用返回值怎么办?

I understand that jquery methods can be applied to the return value, but what if I want to just use the return value directly?

推荐答案

来自 Rick Strahl的描述:

jQuery对象:包装集: 选择器返回已知的jQuery对象 作为包装套",这是 包含所有内容的类数组结构 选定的DOM元素.你可以 像 排列或访问单个元素 通过索引器($(sel)[0]为 例子).更重要的是,您可以 也将jQuery函数应用于 所有选定的元素.

The jQuery Object: The Wrapped Set: Selectors return a jQuery object known as the "wrapped set," which is an array-like structure that contains all the selected DOM elements. You can iterate over the wrapped set like an array or access individual elements via the indexer ($(sel)[0] for example). More importantly, you can also apply jQuery functions against all the selected elements.

关于什么也不返回:

它总是返回一个数组吗?它返回null吗?

Does it always return an array? Does it return null?

您总是会找回同样的东西,无论它是否有任何内容都是问题.通常,您可以使用.val()(例如$('.myElem').val())进行检查

You always get the same thing back, whether or not it has any contents is the question. Typically you can check this by using .val() (e.g. $('.myElem').val())

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

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