js循环找id

<div id="pepole">
    <table>
        <tr><th>Header</th></tr>
        <tr>
            <td>
                <input class="bnt" id="456" type="text" name="" id="" value="" />
            </td>
        </tr>
    </table>
    <table>
        <tr><th>Header</th></tr>
        <tr>
            <td>
                <input class="bnt" id="789" type="text" name="" id="" value="" />
            </td>
        </tr>
    </table>
</div>
var a = document.getElementById("pepole");
var b = a.childNodes;
  
for(i=0;i<b.length;i++){
      
    if(b[i].nodeName == "#text" && !/s/.test(b.nodeValue)){
        a.removeChild(b[i]);
    }
}
  
for (var j = 0; j < b.length; j++) {
      console.log(b[j].querySelector('input').getAttribute('id'));//拿到每一个id
}
原文地址:https://www.cnblogs.com/rockyan/p/9304692.html