zoukankan      html  css  js  c++  java
  • element对象

    1.getAttribute获取属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>element对象</title>
    </head>
    <body>
        <!-- 
         getAttribute属性名
         -->
        <input type="text" id="inputid" value="加油啊,进度有点慢呢">
        <script type="text/javascript">
        var input1 = document.getElementById("inputid");
        //getAttribute得到属性里面的值
        alert(input1.getAttribute("value"));
        alert(input1.getAttribute("id"));
        </script>
    </body>
    </html>


    2.setAttribute设置属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>element对象</title>
    </head>
    <body>
        <!-- 
         getAttribute属性名
         -->
        <input type="text" id="inputid" value="加油啊,进度有点慢呢">
        <script type="text/javascript">
        var input1 = document.getElementById("inputid");
        //设置属性值
        alert(input1.getAttribute("class"));
        input1.setAttribute("class","果子一定要加油");
        alert(input1.getAttribute("class"));
        </script>
    </body>
    </html>


    3.removeAttribute删除属性

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>element对象</title>
    </head>
    <body>
        <!-- 
         getAttribute属性名
         -->
        <input type="text" name="果子请你拼命,不然你会一事无成" id="inputid" value="加油啊,进度有点慢呢">
        <script type="text/javascript">
        var input1 = document.getElementById("inputid");
        //removeAttribute删除属性
        alert(input1.getAttribute("name"));
        input1.removeAttribute("name");
        alert(input1.getAttribute("name"));
        </script>
    </body>
    </html>

    注意:removeAttribute不能删除value属性

  • 相关阅读:
    提升工作效率的方法
    Spark Streaming 实现思路与模块概述
    Reduce Side Join实现
    File file:/data1/hadoop/yarn/local/usercache/hp/appcache/application_* does not exi
    Caused by: java.io.IOException: Filesystem closed的处理
    linux下nproc的作用
    Spark Streaming 的一些问题
    php代码审计7审计csrf漏洞
    php代码审计6审计xss漏洞
    php代码审计5审计命令执行漏洞
  • 原文地址:https://www.cnblogs.com/zjm1999/p/10428597.html
Copyright © 2011-2022 走看看