javascript 在 Angularjs 中获取 ng-keypress 上文本框的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27799750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:00:31  来源:igfitidea点击:

Get value of textbox on ng-keypress in Angularjs

javascriptangularjs

提问by sagar43

I want to get the value of the textbox on keypress.

我想在按键上获取文本框的值。

I have html code like

我有这样的 html 代码

<input style="width: 20%; float: right;" 
       ng-model="que.SelectedOptionsUID" 
       type="text" 
       ng-keypress="myFunct($event)"/>

And JS code on my controller:

我的控制器上的 JS 代码:

$scope.myFunct = function (e) {
    var charCode = (e.which) ? e.which : e.keyCode;
    //i want here value of the textbox 
}

采纳答案by devqon

<input style="width: 20%; float: right;" 
       ng-model="que.SelectedOptionsUID" 
       type="text" 
       ng-keypress="myFunct($event, que.SelectedOptionsUID)"/>

Controller:

控制器:

$scope.myFunct = function (e, myValue) {
    var charCode = (e.which) ? e.which : e.keyCode;        
    // do something with myValue
}