1、绑定自定义属性:

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

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

2、绑定内部规定属性:

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

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

<body>
    <div ></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>

JS——绑定自定义属性

相关文章:

  • 2021-09-20
  • 2021-08-22
  • 2021-12-14
  • 2021-11-21
  • 2021-07-05
  • 2021-06-04
  • 2021-11-29
  • 2021-10-21
猜你喜欢
  • 2021-10-13
  • 2018-05-06
  • 2020-10-06
  • 2021-12-27
  • 2021-10-13
  • 2021-10-21
  • 2021-09-18
  • 2021-04-20
相关资源
相似解决方案