jjzjj

FormElements

全部标签

javascript - 如何在 typescript 中使用表单元素

我想通过myForm.elements访问表单元素,然后通过名称访问每个元素,例如myForm.elements.month。Typescript不喜欢这个b/c它不知道form.elements包含month的属性。我想,让我们创建一个界面吧!所以我做了,(见下面的代码),但我收到了这个typescript错误:Neithertype'HTMLCollection'nortype'FormElements'isassignabletotheother这是我正在使用的代码:interfaceFormElements{day:HTMLInputElement;month:HTMLInpu