文字框中內容被選中能否實現?
阿新 • • 發佈:2018-12-26
最近在使用ionic3做安卓手持時,因業務需要使用者頻繁掃描條形碼,為了提高使用者體驗,想把使用者輸入後的文字內容選中,這樣下一次輸入時就可以直接覆蓋原有內容,而不用手工刪除。那麼問題來了?
ionic3中封裝了input標籤即<ion-input>這個坑貨
<ion-input clearInput="true" type="number" placeholder="請輸入輪胎條碼" (keyup.enter)="focusInputBarcode(barcode,palletNo)" #barcode></ion-input>
ion-input是沒有效果的,需要換成input標籤。
在HTML中對元素新增引用myInput:
<input type="text" #barcode>
在ts中可以通過ViewChild獲取指定元素的引用:
import { ViewChild } from '@angular/core';
@ViewChild('barcode') input;
獲取到對應元素的引用後,你想新增焦點並選中,如下:
this.input.nativeElement.focus();
this.input.nativeElement.select();
原文連結:http://blog.csdn.net/qq_36279445/article/details/78561118