在控制台面板中编辑 HTML 时没有 setAttribute 或 getAttribute

No setAttribute or getAttribute in editing HTML in the Console Panel

我想尝试在 Chrome 的控制台面板中设置属性。

但不使用鼠标。像这样的例子: https://developers.google.com/web/updates/2015/08/edit-html-in-the-console-panel

我只想用命令写JS-CODE,例如:

document.querySelectorAll(".serial-number").setAttribute("Value","dummy");

在控制台面板中 Chrome 这个函数 setAttribute 是不可用的。请问有没有其他方法可以通过设置属性来编写代码?

document.querySelectorAll returns 一个静态的 nodelist,所以需要迭代这个集合,这将允许访问 element.Then setAttribute 可以用来设置一个属性

var getAllLI = document.querySelectorAll('.demoClass');
getAllLI.forEach(function(item, index) {
  item.setAttribute('value', index)
})
<input class="demoClass">
<input class="demoClass">
<input class="demoClass">
<input class="demoClass">