小编Dae*_*lus的帖子

类型'HTMLElement'上不存在Typescript属性'style'

虽然我的代码工作(下面),但是typescript会抛出错误,说"属性'样式'在类型'HTMLElement'上不存在."

正如您所看到的,我通过jQuery和元素的ID抓取元素.

$(this.id).click(function () {
  this.style.display = 'none';
});
Run Code Online (Sandbox Code Playgroud)

但这会导致以下错误:

`TS2339: Property 'style' does not exist on type 'HTMLElement'`.
Run Code Online (Sandbox Code Playgroud)

我不确定处理这个ts错误的正确方法是什么.

有人会让我知道吗?

先感谢您.

更多代码,因为它被请求:

`/**
* Class represents a flash message
*/
export class FlashMessage {    
flashMessageParentDivID:string;
iconID:string;
textID:string;
$: JQuery;

/**
 * 
 * @param {string} flashMessageParentDiv - the string of the div's ID.
 */ 
constructor (flashMessageParentDiv: string, $: JQuery) {
    this.flashMessageParentDivID = "#"+flashMessageParentDiv;
    this.iconID = "#flash-message-icon",
    this.textID = "#flash-message-text";
    this.$ = $;
}

/**
 * Displays the passed in message …
Run Code Online (Sandbox Code Playgroud)

typescript

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

typescript ×1