Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要获取包含输入的 div 的 id,例如:
<div id="example"> <label for="i1">Label1</label> <input id="i1" name="i1" type="text"/> </div>
我希望能帮助我!
您可以尝试:has()选择器:
:has()
$('div:has("input")').attr('id')
演示
$('input').on('click', function(){ alert($(this).parent().attr('id')); });
你的意思是:
$("div:has('input')").attr("id");
或者
$("div").has('input').attr("id");