0

我有我的html文件

<div class="space-between-items">
     <mat-form-field>
        <mat-label>NEC LEC</mat-label>
        <input #neclec matInput formControlName="necLec"  autocomplete="off" 
           [minLength]="NEC_LEC_MIN_LENGTH" [maxLength]="NEC_LEC_MAX_LENGTH"
           [value]="neclec.value.toString().toUpperCase()">
     </mat-form-field>
     <mat-checkbox color="primary" formControlName="chkNecLec"></mat-checkbox>
  </div>

当我保存在此字段中输入内容时,它会像现在一样更新网格。我如何让它自动将大括号添加到我的输入中。

在此处输入图像描述

我希望它一直与大括号一起保存,而不必在输入中手动输入大括号,这样当我输入“REC”时,它会在网格中显示为(REC)。

4

1 回答 1

0

以下解决方案可能对您有用。

function myfunc(value){
    if(!value.startsWith("(")){
    value = "(" + value;
  }
  if(!value.endsWith(")")){
    value = value + ")"
  }
  document.getElementById("abc").value = value;
}
<input id="abc" type="text" onKeyUp="myfunc(value)" value="()"/>

于 2020-07-29T18:50:01.937 回答