在angular js中使用键盘监听事件


 项目中涉及到了搜索框支持回车键调用搜索方法的需求,现作为笔记记录。

html

<input class="search_input" type="text" placeholder="请输入搜索的关键字" ng-model="searchText" ng-keyup="events.keybordSearch($event)"/>

ts

keybordSearch(event:any){
        let $scope = this.$scope;
        let $log = this.$log;

        var keycode = event.keyCode;
        $log.debug("keycode:"+ keycode)
        if(keycode===13){
            $log.debug("点击回车键调用searchVideo()搜索方法")
            //调用搜索方法
            this.searchVideo();
        }
}

其中keycode=13表示回车键,直接调用搜索方法即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM