JQuery:从现有选择器中查找子元素

标签 jquery css-selectors

我确定解决方案很简单,但我无法弄清楚:( 我需要将两个 jquery 选择器合并到一个选择器中:

$(this) + $('input[type=text]:first')

$(this) 是例如 div#selected 所以结果应该是:

$('div#selected input[type=text]:first').focus();

怎么办?

最佳答案

只需使用 .find() :

Get the descendants of each element in the current set of matched elements, filtered by a selector.

$(this).find('input[type=text]:first').focus();

或设置 context:

$('input[type=text]:first', this).focus();

关于JQuery:从现有选择器中查找子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2896938/

相关文章:

DOM 元素数组上的 jQuery 选择行为

javascript - 在 Jasmine 中 mock xhr 调用

html - CSS 选择器分组 : element. 类元素 element.class 元素 - 它选择什么?

javascript - 重定向到新的 URL,但从历史记录中删除以前的 URL

php - 如何使用从 mysql 数据库检索到的值填充下拉列表?

html - 选中复选框时以及单击图像时突出显示图像

css - 在 less css 中定义一个 CSS3 属性选择器

html - CSS3伪类不是第一个和最后一个 child

javascript - 由另一个 ajax 函数触发的 Ajax 函数不起作用

javascript - Wordpress:在另一个插件文件中使用一个插件文件的功能