zoukankan      html  css  js  c++  java
  • js总结33 :javascript-DOM节点属性

    1 设置节点属性三个方法:

    获取:getAttribute(名称)

    设置:setAttribute(名称, 值)

    删除:removeAttribute(名称)

    举个例子:

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <script>
    
    window.onload = function () {
        var eleNode = document.getElementsByTagName("img")[0];
        //1.元素节点.属性或者元素节点[属性]
                eleNode.src = "image/aaa.png";
                eleNode.aaa = "bbb";
                console.log(eleNode.aaa);
                console.log(eleNode.src);
                console.log(eleNode.tagName);
                console.log(eleNode["title"]);
                console.log(eleNode["className"]);
                console.log(eleNode["alt"]);
    
    //2.元素节点.方法();
                console.log(eleNode.getAttribute("id"));
                eleNode.setAttribute("id","你好");
                eleNode.setAttribute("ccc","ddd");
    
                eleNode.removeAttribute("id");
            }
    
       </script>
    </head>
    <body>
    <img src="image/aaa.png" class="box" title="图片" alt="aaa" id="aaa"/>
    </body>
    </html>
  • 相关阅读:
    Ruby(1):入门
    html 制作静态页面新知识
    mysql 可视化界面操作指令
    html 基础
    Eclipse导入Java工程导入错误
    shell 25个常用命令
    java JDBC
    java 8新特性 instant
    git
    spring mvc 注解详解
  • 原文地址:https://www.cnblogs.com/autoXingJY/p/8952891.html
Copyright © 2011-2022 走看看