我使用
const elem = document.getElementById("TcHmiRecipeEdit") console.log(elem);
results:我需要使用JavaScript中的什么代码来获取照片中标记的值。我从JavaScript开始我的冒险,我们有一个巨大的问题,实际上是从代码中提取值,如上面的例子。
68bkxrlz1#
querySelector和querySeletorAll适用于此目的。querySelector,querySelectorAll
querySelector
querySeletorAll
document.querySelectorAll('#TcHmiRecipeEdit table th').forEach(el => { console.log(el.textContent); });
yfjy0ee72#
展开querySelectorAll并MaptextContent
const thVals = [...document.querySelectorAll('#TchmiRecipeEdit table th')] .map(th => th.textContent.trim()); console.log(thVals)
<div id="TchmiRecipeEdit" style="inset: 16px;"> <div class=" TCHES Controls Beckhoff TcHiRecipeEdit template tched-box " tabindex="-1 "> <div class="Tched Controls Beckhoff TcHnRecipeEdit-editing pane "> <div class="TcHed_Controls Beckhoff TcHndRecipeEdit-editing-box"> <div class="Tchad Controls Beckhoff TcHniRecipeEdit-editing-area"> <table> <thead> <tr> <th>Name</th> <th>Value</th> <th>in</th> <th>Unit</th> </tr> </thead> </table> </div> </div> </div> </div> </div>
2条答案
按热度按时间68bkxrlz1#
querySelector
和querySeletorAll
适用于此目的。querySelector,querySelectorAll
yfjy0ee72#
展开querySelectorAll并MaptextContent