gpt4 book ai didi

javascript - removeAttribute 不返回 true 或 false

转载 作者:行者123 更新时间:2023-12-02 20:38:40 24 4
gpt4 key购买 nike

我正在尝试使用 JavaScript 中的以下语句删除 DOM 元素的属性。

var res = nodes.removeAttribute("style");

但是res总是“未定义”,似乎removeAttribute函数没有返回任何内容(我在firefox浏览器上测试过)

如何判断属性是否已成功删除?

谢谢,苏拉卜

最佳答案

node<b>s</b> ?看来你有一个数组 node s。无论如何,removeAttribute不会返回任何东西。要检查该属性是否已被删除,请使用 hasAttribute之后。

node.removeAttribute('foo');
if (node.hasAttribute('foo')) {
// failed, foo still exists.
}

关于javascript - removeAttribute 不返回 true 或 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2849209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com