我有一个奇怪的问题,我如何获取表中所有输入的 id,我不知道该怎么做。
这是我的一些代码
<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>
我对 javascript 和 jquery 很菜鸟,如果你能帮助我那就太棒了!
最佳答案
通过id表获取元素
获取所有子节点> 继续检查子节点,直到找到输入属性。
获取所有带有标签名称输入的子项
对于每个输入的子项获取属性 id。
上面的逻辑将为您提供下面的路径。
document.getElementById("table_id").children[0].childNodes[1].childNodes[7].childNodes[3].id;//输出为“targetpriceinput”
关于javascript - 获取表的 thead 标签内输入的 IDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57914231/