小编给大家分享一下angularjs中响应回车事件的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
下面这个示例在输入框键入回车键或者点击按钮时,将输入框的值置为"Hello World!"
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>angularjs-demo</title>
<script type="text/javascript" src="lib/angularjs/angular.min.js" charset="utf-8"></script>
</head>
<body ng-controller="ctrl">
<input type="text" ng-model="text1" ng-keyup="enterEvent($event)" />
<button ng-click="clickEvent()">test</button>
</body>
<script type="text/javascript">
var app = angular.module('myApp', [])
.controller('ctrl', function($scope){
$scope.clickEvent = function() {
$scope.text1 = "Hello world!";
}
$scope.enterEvent = function(e) {
var keycode = window.event?e.keyCode:e.which;
if(keycode==13){
$scope.clickEvent();
}
}
});
</script>
</html>
看完了这篇文章,相信你对“angularjs中响应回车事件的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网行业资讯频道,感谢各位的阅读!