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属性

  • 相关阅读:
    前端学习之路,新手必看
    css常用的属性方法 上篇
    H5音乐播放器源码地址
    H5音乐播放器源码共享
    H5音乐播放器【歌单列表】
    (1)H5实现音乐播放器【正在播放-歌词篇】
    JS 对数组的操作集锦(基础)
    完整的淘宝页面模板
    一次上机试题(面向对象)
    python select方法的使用
  • 原文地址:https://www.cnblogs.com/zjm1999/p/10428597.html
Copyright © 2011-2022 走看看