javascript - (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>
解决方案
问题正是错误所说的“属性行在 HTMLInputElemet 类型上不存在”。
假设你有<table id="associatedEmailsTable">...
那么你所拥有的是一个HTMLTableElement
. 所以:
var rows = (document.getElementById('associatedEmailsTable') as HTMLTableElement).rows;
推荐阅读
- docker - Jenkinsfile 中的 Dockerfile 构建不一致(连接失败错误)
- html - SyntaxError: Unexpected token / while compile EJS
- php - 使用正则表达式从 url 中查找 Fb Post id
- python - 数据框编辑
- pyqt - PyQT5 - setUnifiedTitleAndToolBarOnMac
- python - 无法将输入数组从形状 (2,2) 广播到形状 (2)
- wordpress - 结帐期间创建帐户 Woocommerce
- ubuntu-18.04 - Dovecot 不在 maildir 中定位消息,如何解释调试日志?
- excel - .Find 后存储范围值
- c - 带有 PTRACE_O_EXITKILL 的 PTRACE_SETOPTIONS 不起作用:参数无效