我使用,(请不要介意选择器,我知道它应该改变,但它仍然被发现)。当使用element.style = <some CSSStyleDeclaration>使元素消失
let leftArrow = <HTMLElement> document
.querySelector('div[style="position: absolute; left: 6px; transform: skewX(22.6deg);' +
' transform-origin: 0px 0px 0px; height: 24px; width: 10px;' +
' box-shadow: rgba(0, 0, 0, 0.6) 0px 1px 6px; background-color: rgb(255, 255, 255);"]');
然后我用:
let myStyle = leftArrow.style; //this gets me a CSSStyleDeclaration object
console.log(myStyle); // those are equal objects
console.log(leftArrow.style); // those are equal objects
但是当我做:
leftArrow.style = myStyle; //this should change nothing ?!
我的元素dissappears?!
我的目标是使用一个类,然后折腾这样的:
leftArrow.style = myStyle;
从上一个我的元素变成:
leftArrow.style = this.getStyleFromClass(selector_to_find_class_name);
但经过简单的
<div></div>
这使得它基本上不可见。为什么?
是否有在控制台中的任何错误消息? –
您是否尝试恢复应用的样式?你将需要以不同的方式来解决这个问题。 – epascarello