zoukankan      html  css  js  c++  java
  • JS——绑定自定义属性

    1、绑定自定义属性:

    (1)元素节点.属性或元素节点[属性]绑定的属性不会出现在标签中,setAttribute可以出现在标签中。

    (2)setAttribute获取不到元素节点.属性形式绑定的属性值,同样元素节点.属性也获取不到setAttribute绑定的属性值

    2、绑定内部规定属性:

    (1)元素节点.属性或元素节点[属性]会出现的标签中,setAttribute也出现在标签中。

    (2)setAttribute可以获取元素节点.属性形式绑定的属性值,同样元素节点.属性也可以获取到setAttribute绑定的属性值

    <body>
        <div id="box"></div>
        <script>
            var box = document.getElementById("box");
            box.add = "add";
            console.log(box.add);//add
            box.setAttribute("yes", "yes");
            console.log(box.getAttribute("yes"));//yes
            console.log(box.yes);//undefined
            console.log(box.getAttribute("add"));//null
        </script>
    </body>

  • 相关阅读:
    006 date find
    005 输出重定向 > >>命令 echo命令 tail命令
    总结,一周,
    mokey 学习
    树状,
    定制,
    萌芽,
    到底为什么,
    会,
    “恋爱”,一路走来,
  • 原文地址:https://www.cnblogs.com/wuqiuxue/p/7874586.html
Copyright © 2011-2022 走看看