querySelector的用法

    xiaoxiao2025-04-19  9

    在js中可以通过标签选择器获取标签,现在发现还有querySelector可以实现选择器的功能。

    js的用法:

    <label>hhh22</label> <label id="la">hhh</label> <script> alert(document.getElementById('la').innerHTML); </script>

    打印结果:

    hhh

    querySelector的用法:

    <label>hhh22</label> <label id="la">hhh</label> <script> alert(document.querySelector('label').innerHTML); alert(document.querySelector('label[id=la]').innerHTML); </script>

    打印结果:

    hhh22 hhh
    转载请注明原文地址: https://ju.6miu.com/read-1298226.html
    最新回复(0)