JQuery:从现有选择器中查找子元素 [英] JQuery: find child elements from an existing selector

查看:22
本文介绍了JQuery:从现有选择器中查找子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定解决方案很简单,但我想不通:(我需要在一个选择器中组合两个 jquery 选择器:

Im sure the solution is simple but I cant figure it out :( I need to combine two jquery selectors in one selector:

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

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

$(this) is e.g div#selected so the result should be:

$('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:从现有选择器中查找子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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