gpt4 book ai didi

javascript - 如何找到非间接/嵌套的父级的子级

转载 作者:行者123 更新时间:2023-12-02 23:45:36 24 4
gpt4 key购买 nike

我需要找到某个类,然后找到一个在其下面嵌套了多个元素的输入。我需要目标类名称来附加它。

我以为我可以使用 .queryselector 但似乎不行。我无法在输入中使用 ID。

var input = document.querySelectorAll('.pt-page.pt-subpage-current input');
var solve = input[0];

console.log(solve);
<div class="pt-page pt-subpage-current"> /*only identifier*/
<div class="container">
<div class="question">
<div class="input">
<input name="school" type="text" id="schoolCode1" autocomplete="off">/*target*/
</div>
</div>
</div>
</div>

我以为我可以像上面一样使用查询选择器(我已经经历了多次迭代),但没有骰子。

最佳答案

Use the direct descendant selector >

$('#mainDiv > p:first')

or even children()

$('#mainDiv').children('p').first()

关于javascript - 如何找到非间接/嵌套的父级的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55869709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com