首页 > 解决方案 > (TS) 属性行在 HTMLInputElemet 类型上不存在

问题描述

嗨,我是角度和类型脚本的新手。我需要检查表是否为空,并根据需要隐藏或显示 div。我试过了,

var rows = document.getElementById('associatedEmailsTable'))rows;
var rows =(<HTMLInputElement>document.getElementById('associatedEmailsTable')).rows;

但两者都给出相同的结果,请帮助我。

请建议我如何使用 javascript 找到 table tr 里面是否有任何值。

我的 HTML 代码是

   <table class="table table-sm table-hover" id="associatedEmailsTable" style="display:none">
       <tr>
            <th>
              Email
            </th>
            <th>
              Action
            </th>
          </tr>
          <tr *ngFor="let oEmailAddress of this.associatedEmailAddresses">
            <td>{{oEmailAddress.email}}</td>

          </tr>
        </table>

标签: javascriptangularhtmltypescript

解决方案


问题正是错误所说的“属性行在 HTMLInputElemet 类型上不存在”。

假设你有<table id="associatedEmailsTable">...那么你所拥有的是一个HTMLTableElement. 所以:

var rows = (document.getElementById('associatedEmailsTable') as HTMLTableElement).rows;

推荐阅读