zoukankan      html  css  js  c++  java
  • js

    1.

    用.和[]的形式无法操作元素的自定义属性; getAttribute可以操作元素的自定义属性
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <input type="text" id="text1" value="1111" _name = "miaowei"><br>
    <img src="img/1.png" alt="无图" id="img1" style=" 100px; height: 100px">
    
    <script>
        window.onload = function () {
            var oText = document.getElementById('text1');
            var oImg = document.getElementById('img1');
            oText.value = '2222';
            alert(oText.value); //2222
    
            oText['value'] = '3333';
            alert(oText['value']); //3333
            alert(oText.getAttribute('value')) //1111
    
            // 设置属性值
            oText.setAttribute('value', '你好,世界');
            alert(oText.getAttribute('value')) // 你好,世界
    
            //移除属性
            oText.removeAttribute('value');
            alert(oText.getAttribute('value')) // null
    
            //用.和[]的形式无法操作元素的自定义属性 ; getAttribute可以操作元素的自定义属性
            alert(oText._name); //undefined
            alert(oText['_name']); //undefined
            alert(oText.getAttribute('_name')); //miaowei
            console.log(oImg.src + ":" + oImg['src'] + oImg.getAttribute('src')); //http://localhost:63342/helloworld/img/1.png
        }
    </script>
    
    </body>
    </html>
    
  • 相关阅读:
    JSP自定义标签
    Java集合之Arrays 剖析
    关于Java8中的Comparator那些事
    关于Comparable和Comparator那些事
    浅析Thread的join() 方法
    多线程的具体实现
    如何实现 List 集合的线程安全
    集合使用 Iterator 删除元素
    Tomcat目录详解
    一文读懂微服务架构
  • 原文地址:https://www.cnblogs.com/bravolove/p/5996930.html
Copyright © 2011-2022 走看看