"js获取元素节点的方式有哪些?"

js获取元素节点的方式有哪些?

  1. document.getElementById()
  2. document.getElementsByClassName()
  3. document.getElementsByTagName()
  4. document.querySelector()
  5. document.querySelectorAll()
  6. document.getElementsByName()
  7. document.body、document.links、document.images、document.forms、document.iframes、document.tables等
    8、document.elementFromPoint(x,y)
    9、直接id,因为id是保存到window对象上的全局变量
<p id="p">Hello world</p>
<script>
    p.style.color = '#f00';
</script>
PS:写作不易,如要转裁,请标明转载出处。
登录
注册
回顶部