我想在javascript中使用下面的语句去除DOM元素的属性。removeAttribute不返回true或false
var res = nodes.removeAttribute("style");
但资源永远是“不确定”似乎的removeAttribute函数不返回任何东西(我测试了Firefox浏览器)
我如何确定该属性被成功删除或不?
感谢, Sourabh
我想在javascript中使用下面的语句去除DOM元素的属性。removeAttribute不返回true或false
var res = nodes.removeAttribute("style");
但资源永远是“不确定”似乎的removeAttribute函数不返回任何东西(我测试了Firefox浏览器)
我如何确定该属性被成功删除或不?
感谢, Sourabh
nodes
?看起来你有一组node
s。无论如何,removeAttribute
不会返回任何东西。要检查属性是否已被删除,请使用hasAttribute
。
node.removeAttribute('foo');
if (node.hasAttribute('foo')) {
// failed, foo still exists.
}
http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-removeAttribute - “这个方法返回什么。” – bobince 2010-05-17 14:05:14