我确定解决方案很简单,但我无法弄清楚:( 我需要将两个 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/