获取所有s开头的标签

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span>我是个span1</span>
    <span>我是个span2</span>
    <section>我是个section</section>
    <script>
        const all = Array.from(document.all);
        const res  = all.filter(item=>/^[s]/.test(item.localName))
        console.log(res);
    </script>
</body>
</html>
发布了79 篇原创文章 · 获赞 9 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_33807889/article/details/105231409