zoukankan      html  css  js  c++  java
  • 元素节点的获取的六种方法

     
    <html>
    <head>
    </head>
    <body>



        <script>
            //1 通过标签的id属性获取元素
            document.getElementsById(参数)
            // 注意:
            // 1)参数不需要加#
            // 2)id值相同时只能获取第一个
            // 3)参数区分大小写
            // 2 通过标签名来获取元素(类似数组)
            document.getElementsByTagName(参数)
            // 注意:
            // 1)参数不区分大小写
            // 2)返回值为“伪数组”,可以通过下标获取其中某个元素
            // 3 通过标签的name属性来获取元素(类似数组)
            // 4 通过标签的class属性来获取元素
            //(数组),有浏览器兼容性,主要是ie8以下
            var list = document.getElementsByClassName('sty');
            //5 通过css选择器获取页面元素
            var objs = document.querySelector('div,p');
            console.log(objs);
            //6 通过css选择器获取页面元素
            var objs = document.querySelectorAll('div,p');
            console.log(objs);
        </script>
    </body>
    </html>
    一日之计在于晨
  • 相关阅读:
    Microsoft Azure 微软云平台系列新品发布
    python学习笔记(三)
    python学习笔记(一)
    python GUI编程(tkinter)
    python Tkinter之Button
    tkinter比较常用的组件
    tkinter窗口系列之一——列表框
    tkinter模块中常用的参数
    python的字符串操作函数之一览
    python之闭包
  • 原文地址:https://www.cnblogs.com/1998Archer/p/12586672.html
Copyright © 2011-2022 走看看