簡體   English   中英

如何在 HTML 代碼中為 HTML 元素的 id 設置變量的值?

[英]How to set the value of variable for id of HTML-element in HTML-code?

例如, counter是我的變量。

我想做這樣的:

<input id="counter(I mean value of counter)" type="text" mozactionhint="next" name="sometext" />

或者,例如:

<table>
  <tbody>
    <tr *ngIf="currentNode?.parameters.length != 0">
      <td align="center">Type</td>
      <td align="center">Key</td>
      <td align="center">Value</td>
    </tr>
    <tr *ngFor="let item of getParametersWithoutName(); index as i;">
      <td>
        <select>
          <option>One-line</option>
          <option>Multiline</option>
        </select>
      </td>
      <td>< id="i (value of i)" input [ngModel]="item.name" (ngModelChange)="item.name = $event"/></td>
      <td><input [ngModel]="item.value" (ngModelChange)="item.value = $event"/></td>
    </tr>
  </tbody>
</table>

如果要動態設置 angular 中元素的 id,可以使用括號表示法,如下所示:

// component.ts

counter = 1;


// template.html

<input [id]="counter"> </input>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM