是否可以使用JavaScript删除元素的CSS属性? 例如,我有div.style.zoom = 1.2, 现在我想通过JavaScript删除缩放属性?
当前回答
你可以使用styleSheets对象:
document.styleSheets[0].cssRules[0].style.removeProperty("zoom");
警告#1:您必须知道样式表的索引和规则的索引。
警告#2:该对象由浏览器实现不一致;在一种情况下有效的方法在另一种情况下不一定有效。
其他回答
removeProperty将从元素中删除一个样式。
例子:
div.style.removeProperty(“变焦”);
MDN文档页面: CSSStyleDeclaration.removeProperty
div.style.removeProperty('zoom');
你也可以在jQuery中这样做:$(selector).css("zoom", "")
这应该做的技巧-设置内联样式为正常缩放:
$ (' div ')。attr(“风格”,“变焦:正常;”);
你可以使用styleSheets对象:
document.styleSheets[0].cssRules[0].style.removeProperty("zoom");
警告#1:您必须知道样式表的索引和规则的索引。
警告#2:该对象由浏览器实现不一致;在一种情况下有效的方法在另一种情况下不一定有效。