因为ts默认用的是Element,需要声明为HTMLElement
let top = <HTMLImageElement>document.querySelector('.Top');
top.style.display = 'none' ;
或是下面这样
let top = document.querySelector('.Top') as HTMLElement;
top.style.display = 'none' ;
当然如果你用的是angular的话,建议用 ElementRef
import { Component, ElementRef } from '@angular/core';
constructor(
private elementRef: ElementRef
) {
}
this.elementRef.nativeElement.querySelector('#select_id');