Jquery-通过父级输入focus()并查找嵌套元素类
我有这个html。使用JQuery如何在单击Jquery-通过父级输入focus()并查找嵌套元素类,jquery,html,Jquery,Html,我有这个html。使用JQuery如何在单击 我在想这样的事情: $('.mm-subopen').click(function () { //find this.class parent, parent (witch would be: <li class="img no-arrow join">) //and then trough: <li class="img no-arrow join"> find the input in same
我在想这样的事情:
$('.mm-subopen').click(function () {
//find this.class parent, parent (witch would be: <li class="img no-arrow join">)
//and then trough: <li class="img no-arrow join"> find the input in same scope and get it focused
});
$('.mm子笔')。单击(函数(){
//查找this.class parent,parent(将是:)
//然后通过: 在相同的范围内找到输入并使其集中
});
任何帮助都将不胜感激 您可以替换链接
<a class="mm-subopen" href="#clickMe"></a>
我想这就是你的想法
$('.mm-subopen').click(function () {
$(this).parents("li").find(":input").focus();
});
这里有一个我需要在js中完成,因为
href=“#clickMe”
在我的代码的许多其他部分都使用。Iv'e尝试了你的js解决方案,但不起作用。我的
标记在加载文档时动态构建。这可能是个问题吗?是的,这可能是个问题。试试这个$(文档).on('click','.mm subopen',function(){$(this).closest('li').find('input').focus();})代码>。奇怪,还是不起作用。我以为你最后一次送的人会修好的。你知道这里还有什么问题吗?有什么建议吗?嗯,不确定。你能用小提琴复制这个问题吗?顺便问一下,聊天输入必须是li
元素,而不是div
。
<label class="mm-subopen" for="studio123"></label>
$('.mm-subopen').click(function () {
$(this).closest('li').find('input').focus();
});
$('.mm-subopen').click(function () {
$(this).parents("li").find(":input").focus();
});