最佳答案
密码是这样的:
const test = Array.from(document.getElementsByClassName('mat-form-field-infix'));
test.forEach((element) => {
element.outerHTML = '<div class="good-day-today" style="width: 0px;"></div>'; // Please note that this line works fine!
element.style.padding = '10px';
element.style.borderTop = '0';
});
编译时出现的错误:
Src/app/< em >/ .Component. ts (101,21)中的错误: ERROR TS2339: Property 类型“ Element”上不存在“ style”。 Src/app/< em >/ .Component. ts (102,21) : error TS2339: Property‘ style’(102,21) : 错误 TS2339: 属性‘ style’ 类型“ Element”上不存在。
我该怎么补救?
我尝试去除 Array.from...的部分,尝试使用 for of和 for in,尝试 as any,但以上是我必须做到这一点的方式。