可以使用下面的两种方法将一个新创建的属性节点设置到特定元素节点上.

var node = document.getElementById('div1');

var a = document.createAttribute('my_attrib');
a.value = 'newVal';

node.setAttributeNode(a);
// 或者
node.setAttribute('my_attrib', 'newVal');

 

注意: 这里的属性名和属性值可以自定义.

相关文章:

  • 2022-01-12
  • 2022-02-07
  • 2022-12-23
  • 2022-02-16
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
相关资源
相似解决方案