我正在尝试使用javascript中的以下语句删除DOM元素的属性。
var res = nodes.removeAttribute("style");
但res总是“未定义”似乎removeAttribute函数没有返回任何内容(我在firefox浏览器上测试过它)
如何识别属性是否已成功删除?
谢谢, Sourabh
答案 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”);