zoukankan      html  css  js  c++  java
  • Dom元素的操作

    getElementById(): 获取有指定惟一ID属性值文档中的元素

    getElementsByName(name): 返回的是数组

    getElementsByTagName(): 返回具有指定标签名的元素子元素集合

    getAttribute(): 返回指定属性名的属性值

    1
    document.getElementsByTagName("a")[0].getAttribute("target");

    setAttribute(): 添加指定的属性,并为其赋指定的值。

    1
    document.getElementsByTagName("INPUT")[0].setAttribute("type","button");

    节点属性:

    节点名称(只读):nodeName

    节点值: nodeValue

    节点类型(只读):nodeType

    子节点:

    ele.childNodes 返回数组

    firstChild

    lastChild

    父节点

    parentNode 只有一个

    兄弟节点

    nextSibling 某节点之后紧跟的节点

    previousSibling

    插入节点

    appendChild() 插入在最后

    insertBefore(newnode,node)在node节点之前

    删除节点

    removeChild(node) 成功返回被删除的节点 失败返回null

    替换元素节点

    replaceChild(newnode,oldnode) 实现子节点对象的替换

    创建元素节点

    createElement()

    创建文本节点

    createTextNode()

    复制节点

    需要被复制的节点.cloneNode(true/false)

    true复制当前节点极其所以子节点,false仅复制当前节点

  • 相关阅读:
    spring boot项目接入xxl-job
    Vue3 目录结构
    [原创]阿里全链路压测学习及理解
    python测试开发django-107.form组件widgets(radio/checkbox/单选多选下拉框/日历控件)
    ubuntu通过nginx部署fastcgi程序
    fastcgi
    fpc protobuf开源框架
    delphi jwt
    JWT
    google protobuf经验
  • 原文地址:https://www.cnblogs.com/jimmy1293/p/6198335.html
Copyright © 2011-2022 走看看