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>
    
  • 相关阅读:
    辞职后的第二个星期
    最近似乎应该休眠了.
    文件.二进制转换
    AVL树
    ajax 的同步和异步
    在SQL Server实现最短路径的搜索
    网页嵌套com例子
    Vs2005 dll 设置def导出函数
    [转]ATL开发一个ActiveX
    Atl COM发布与优化
  • 原文地址:https://www.cnblogs.com/bravolove/p/5996930.html
Copyright © 2011-2022 走看看