如何删除 D3.js 中的属性?

2022-01-13 00:00:00 attributes d3.js dom javascript

我可以在 D3.JS 中删除属性吗?我已经使用 .attr("disabled", "disabled") 添加了它,现在我正在寻找类似于 jQuery 的 .removeAttr("disabled", "disabled"); 再次删除它.对于 <button><option> 很有用.我试过使用 .remove() 但这会删除整个对象而不是属性.

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.

推荐答案

来自 API 文档 <代码>属性

空值将删除指定的属性

所以看起来你想要 .attr('disabled', null).

相关文章