removeAttribute不返回true或false

时间:2010-05-17 13:02:53

标签: javascript

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

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

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

如何识别属性是否已成功删除?

谢谢, Sourabh

2 个答案:

答案 0 :(得分:2)

nodes?看来你有一个node的数组。无论如何,removeAttribute将不会返回任何内容。要检查该属性是否已被删除,请在之后使用hasAttribute

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

答案 1 :(得分:0)

nodes.removeAttribute( “风格”);

var isTheLanguageWorkingLikeItShouldAndThisCheckIsTotallyPointless = nodes.getAttribute(“style”);

相关问题