浅谈angularjs中响应回车事件
程序员文章站
2023-02-19 20:14:28
下面这个示例在输入框键入回车键或者点击按钮时,将输入框的值置为"hello world!":(黄色背景内容为响应回车事件涉及到的代码)
下面这个示例在输入框键入回车键或者点击按钮时,将输入框的值置为"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中响应回车事件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。