嗨,我是 Angular 和类型脚本的新手。我需要检查表格是否为空,并根据需要隐藏或显示 div。我试过了,
var rows = document.getElementById('associatedEmailsTable'))rows;
和
var rows =(<HTMLInputElement>document.getElementById('associatedEmailsTable')).rows;
但两者都给出相同的结果,请帮助我。
请建议我如何使用 javascript 查找表 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>
最佳答案
问题正是错误所说的“HTMLInputElemet 类型上不存在属性行”。
假设您有 <table id="associatedEmailsTable">...
那么你拥有的是 HTMLTableElement
。
所以:
var rows = (document.getElementById('associatedEmailsTable') as HTMLTableElement).rows;
关于javascript - (TS)HTMLInputElement 类型上不存在属性行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51016858/