代码之家  ›  专栏  ›  技术社区  ›  Chanaka Amarasinghe

如何打开和关闭输入复选框(更改)事件值?

  •  2
  • Chanaka Amarasinghe  · 技术社区  · 6 年前

    结果总是显示为“开”。我想让它在开关时有两个结果。

      <label class="switch switch-3d switch-primary switch-success">
        <input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.value)" id="ifLimitAccess" class="switch-input">
        <!-- [attr.disabled]="switchDisable?'':null"  [checked]="switchEnable" -->
        <span class="switch-label" data-on="Yes" data-off="No"></span>
        <span class="switch-handle"></span>
      </label>
    
    3 回复  |  直到 6 年前
        1
  •  3
  •   Azamat Zorkanov    6 年前

    只是使用 选中的 属性:

    <input type="checkbox" (change)="isChangeLimitAccessToggle($event.target.checked ? 'on' : 'off')" id="ifLimitAccess" class="switch-input">
    
        2
  •  1
  •   Michael Desigaud    6 年前

    将[(ngmodel)]指令添加到输入:

    <label class="switch switch-3d switch-primary switch-success">
    <input type="checkbox" [(ngModel)]="checkboxValue"(change)="isChangeLimitAccessToggle(checkboxValue)" id="ifLimitAccess" class="switch-input">
    <!-- [attr.disabled]="switchDisable?'':null"  [checked]="switchEnable" -->
    <span class="switch-label" data-on="Yes" data-off="No"></span>
    <span class="switch-handle"></span>
    

        3
  •  0
  •   Nagender Pratap Chauhan    6 年前
    <input type="checkbox" value = "1"(change)="isChangeLimitAccessToggle($event.target.value)"  class="switch-input">
    

    您可以在输入标记中传递值,当您单击复选框时,您会得到1个值,这样它就可以为您工作了。