Javascript 财产';伪风格';不存在于类型';HTMLElement';
我正在尝试使用Typescript修改伪元素的高度 我的IDE(vscode)中出现以下错误 这是我的密码Javascript 财产';伪风格';不存在于类型';HTMLElement';,javascript,angular,typescript,ionic3,pseudo-element,Javascript,Angular,Typescript,Ionic3,Pseudo Element,我正在尝试使用Typescript修改伪元素的高度 我的IDE(vscode)中出现以下错误 这是我的密码 // select element let el: HTMLElement = document.getElementById('filter-container'); // style the height of psydo element el.pseudoStyle("before", "height", newHeight); ... 尝试el.prototype.pseudo
// select element
let el: HTMLElement = document.getElementById('filter-container');
// style the height of psydo element
el.pseudoStyle("before", "height", newHeight);
...
尝试
el.prototype.pseudoStyle(“before”,“height”,newHeight)代码>正如我在JavaScript中所知道的,我们不能更改伪元素,我猜TS中也是如此,因为它是一个JS超集。
非常感谢。您不能仅在特定元素上设置伪类的样式,您可以通过更改样式表来实现:
document.styleSheets[0].insertRule('#id:hover { background-color: blue; }', 0);
document.styleSheets[0].cssRules[0].style.backgroundColor= 'blue';
HTMLElement
接口中没有pseudoStyle
属性。这就是它在IDE中抛出错误的原因。您可以这样做let el:any=document.getElementById('filter-container')代码>@BasavarajBhusani我尝试了any,它给出了错误el.pseudoStyle不是函数您在VS代码IDE中或在运行时收到该错误吗?@BasavarajBhusani在运行时