JQuery:从现有选择器中查找子元素
我确定解决方案很简单,但我无法弄清楚:(我需要在一个选择器中组合两个jquery选择器:
$(this) + $('input[type=text]:first')
$(this)是例如div#selected所以结果应该是:
$('div#selected input[type=text]:first').focus();
怎么做?
只需使用.find()
:
获取当前匹配元素集中每个元素的后代,由选择器过滤。
$(this).find('input[type=text]:first').focus();
或者将上下文设置为:
$('input[type=text]:first', this).focus();
您可以使用多个以逗号分隔的选择器:
我想你正在寻找:
$('input[type=text]:first', this).focus();
它将输入框集中在div#selected
的上下文中
$(this).children('#inpouter[type=test]:first').focus();
应该做的诀窍……