ionic 2.x 3.x input触发调用键盘搜索及事件

时间:2023-03-09 07:09:28
ionic 2.x 3.x input触发调用键盘搜索及事件

html

(1、input  type='search'   2、将input套在一个带action的form中 )

  <form action="">
<ion-input type="search" placeholder="请输入搜索关键字" (keypress)='test($event)'></ion-input>
</form>

typescript

(监听input的keypress事件)

  test(event) {
if (event && event.keyCode == 13) {
alert('yes');
}
}

补充:关闭input自动完成

 autocomplete='off'
        <form action="">
<input autocomplete='off' class="usIndexsch" type="search" name='key' placeholder="目的地/关键词" [(ngModel)]='key' (keypress)='keySelect($event)'>
</form>