小编Vig*_* SP的帖子

验证是否在Angular2中选中了输入复选框

我的HTML中有一个表格,每行的一个单元格中都有一个输入复选框

现在,我尝试检查复选框是否已选中,以下是我尝试过的操作。

HTML:

<table class="table table-hover" id="just_a_table">
    <thead>
        <tr>
          <th scope="col">Select</th>
          <th scope="col">IP Addr</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let data of instances">
          <td><input type="checkbox" (click)='onSelect()'></td>
          <td>{{data["IP"]}}</td>
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

TS:

onSelect() {
    // We get the table data from the html and find if the checkbox is active.
    // The rows of the tables can be accessed by "rows" object and cells can be accessed using "cells" object.
    this.table_data = document.getElementById("just_a_table")

        for (var i=1, row; row …
Run Code Online (Sandbox Code Playgroud)

typescript angular

5
推荐指数
1
解决办法
2725
查看次数

标签 统计

angular ×1

typescript ×1