javascript 如何删除 D3.js 中的属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15322556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove an attribute in D3.js?
提问by bonna
Can I in D3.JS remove an attribute? I've added it using .attr("disabled", "disabled")
and now I am looking for something similar to jQuery's .removeAttr("disabled", "disabled");
to remove it again. Useful for <button>
and <option>
. I've tried using the .remove()
but that removes the entire object not the attribute.
我可以在 D3.JS 中删除一个属性吗?我已经添加了它.attr("disabled", "disabled")
,现在我正在寻找类似于 jQuery 的东西来.removeAttr("disabled", "disabled");
再次删除它。对<button>
和有用<option>
。我试过使用.remove()
但删除整个对象而不是属性。
回答by Ian Roberts
From the API documentation for attr
A null value will remove the specified attribute
空值将删除指定的属性
So it looks like you want .attr('disabled', null)
.
所以看起来你想要.attr('disabled', null)
。