如何使用PrototypeJS删除属性

Nic*_*ndo 3 html javascript prototypejs

我从谷歌搜索中看到的唯一一件事是

Element.writeAttribute() - 添加,指定或删除作为散列或名称/值对传递的属性.

但是,我看到的唯一示例是添加/修改和属性/值,而不是删除.

说我有html元素

<input id="chk" type="checkbox" class="myclass" checked="checked" />
Run Code Online (Sandbox Code Playgroud)

如何checked使用PrototypeJS 删除属性?

p.s*_*w.g 5

快速查看源代码显示:

function writeAttribute(element, name, value) {
  …
  if (value === false || value === null)
    element.removeAttribute(name);
  …
}
Run Code Online (Sandbox Code Playgroud)

所以只是这样调用就可以了:

$("chk").writeAttribute("checked", false);
Run Code Online (Sandbox Code Playgroud)

示范