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——绑定自定义属性

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案