javascript - 获取表的 thead 标签内输入的 IDS

标签 javascript jquery html

我有一个奇怪的问题,我如何获取表中所有输入的 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/

相关文章:

javascript - 处理嵌套上下文提供程序

javascript - 自动执行匿名 JavaScript 函数的括号位置?

javascript - 如何检查浏览器是否支持公钥凭据?

javascript - jQuery 仅适用于某些 id 标签

javascript - 嵌入的 svg 何时实际加载,我如何检查它是否加载

javascript - JS中如何将一维数组转换为列向量

php - 使用需要 MySQL 查询 + PHP 的 AJAX 刷新 DIV

javascript - 使用 jquery 从 JSON 数据创建动态复选框

javascript - 如何将单选按钮行为添加到 <a>

html - 将焦点状态的 CSS 颜色移除为当前颜色