如何在打字稿中添加innerhtml?

Niv*_*a G 3 typescript

我在我的应用程序中使用打字稿。

html代码:

<input type="text" name="lastname" id="last">
Run Code Online (Sandbox Code Playgroud)

打字稿代码:

let myContainer = <HTMLElement>document.getElementById('last');
myContainer.innerHTML = "";
Run Code Online (Sandbox Code Playgroud)

我想使用打字稿为姓氏字段设置空值。我正在使用上面的代码。但无法使用打字稿添加空值。

我还尝试使用以下代码:

document.getElementById('last').innerHTML = "";
Run Code Online (Sandbox Code Playgroud)

如何使用打字稿为文本框分配空值?

Nit*_*mer 5

Html 输入元素具有 value 属性,因此它应该是:

let myContainer = document.getElementById('last') as HTMLInputElement;
myContainer.value = "";
Run Code Online (Sandbox Code Playgroud)

请注意,我还使用HTMLInputElementHTMLElementwhich 没有value属性。