Javascript 获取表的thead标记中的输入ID
我有一个奇怪的问题,我怎么才能得到我表的thead中所有输入的id,我不知道怎么做 这是我的一些代码Javascript 获取表的thead标记中的输入ID,javascript,jquery,html,Javascript,Jquery,Html,我有一个奇怪的问题,我怎么才能得到我表的thead中所有输入的id,我不知道怎么做 这是我的一些代码 <table id="table_id" class="display" style="width:100%"> <thead class="table-head"> <tr> <th> Company </th>
<table id="table_id" class="display" style="width:100%">
<thead class="table-head">
<tr>
<th>
Company
</th>
<th>Symbol</th>
<th>Rating</th>
<th>Target Price<br>
<input id="targetpriceinput" type="number" value="0" placeholder="set min" style="width:100px;">
</th>
<th>Upside<br>
<input id="upsideeinput" type="number" value="0" placeholder="set min" style="width:100px;">
</th>
<th>Price<br>
<input id="upsideeinput" type="number" value="0" placeholder="set min" style="width:100px;">
</th>
<th>Mkt Cap</th>
<th>Price Performance 1M</th>
</tr>
</thead>
</table>
单位
象征
评级
目标价格
上行
价格
总市值
性价比100万
我不懂javascript和jquery,如果你能帮我的话,那就太棒了 如果只有一个元素,则可以将其用作选择器:
const inputs = document.querySelectorAll('thead input');
const ids = [... inputs].map(i => i.id);
console.log(ids);
请注意,如果您有没有id的输入,则会有空值。如果您只有一个元素,则可以将其用作选择器:
const inputs = document.querySelectorAll('thead input');
const ids = [... inputs].map(i => i.id);
console.log(ids);
请注意,如果您的输入没有id,则将有空值
获取所有子节点>继续检查子节点,直到找到输入属性。
获取带有标记名输入的所有子项
对于每个输入,AD子级获取属性id。
上面的逻辑将为您提供下面的路径
document.getElementById(“表id”).children[0]。childNodes[1]。childNodes[7]。childNodes[3]。id;//输出为“targetpriceinput”
按id表获取元素
获取所有子节点>继续检查子节点,直到找到输入属性。
获取带有标记名输入的所有子项
对于每个输入,AD子级获取属性id。
上面的逻辑将为您提供下面的路径
document.getElementById(“表id”).children[0]。childNodes[1]。childNodes[7]。childNodes[3]。id;//输出为“targetpriceinput”