javascript - 为什么这个 jQuery 选择器有效?它基于什么?

标签 javascript jquery jquery-mobile jquery-selectors

this question ,使用了以下代码-

var parent = $("#jcontent"); 
var button1 = $(".button1", parent) ;

在 id jcontent 的父级中选择类 button1 的按钮。

为什么会这样?将 jQuery 对象作为参数传递给 jQuery 选择器如何告诉它在该对象内进行选择?有人可以链接到解释此功能的文档吗?

最佳答案

它是 core method callcontext 参数.

参数描述为:

A DOM Element, Document, or jQuery to use as context

然后是标有“选择器上下文”的部分,其开头为:

By default, selectors perform their searches within the DOM starting at the document root. However, an alternate context can be given for the search by using the optional second parameter to the $() function.

关于javascript - 为什么这个 jQuery 选择器有效?它基于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11127295/

相关文章:

javascript - Angularjs 复选框选中了 onload,但在嵌套 ng-repeat 内第一次未选中时给出了 undefined

javascript - 当我尝试单击 Shift + Tab 组合时,会触发 Shift 键

JQuery Mobile 更改页面

Jquery-mobile data-role=内容澄清

javascript - 启动时仅显示一次 jquery 移动对话框(网络应用程序)

javascript - 不是 Angular js中的数字

javascript - 图像在 Chrome 和 IE 中显示不同

jQuery 向左滑动并显示

javascript - 有条件地应用点击时更改的类

javascript - 使用sheerock js回调创建变量