Firefox浏览器问题

时间:2016-08-24 07:40:23

标签: javascript angularjs events

我在angularJS中编写了基本代码来打印用户输入。它使用chrome而不是firefox。附加了html和js文件。任何人都可以帮我解决这个问题。

var application = angular.module('mainApp', []);
application.controller('app', function($scope){
	$scope.Inputs = [];
	$scope.searchEnter = function() {
		if(event.which == 13 && $scope.Input != "")
		{
			$scope.addInput();
		}
	};
	$scope.addInput = function(){
		$scope.Inputs.push($scope.Input);
		$scope.Input = '';
		};
});	
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>get the input from user and print on page</title>
		 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
		 <script src="controller.js"></script>
		</head>
				<body ng-app="mainApp" ng-controller="app">
					<h2 style="color:blue"> Enter the input value</h2>
					<input type="text" ng-model="Input" ng-keyup="searchEnter()">
					<div id="InputsToPrint">
						<ol>
							<li style="font-size:14px; font-weight:bold; text-transform:capitalize; font-style=italic; color:green" ng-repeat="firstInput in Inputs">
								{{firstInput}}
							</li>
						</ol>
					</div>
				</body>
</html>

在firefox中输入值不在页面中打印。

1 个答案:

答案 0 :(得分:0)

您尚未将event对象传递给函数。您应该在调用$event方法时传递searchEnter(事件对象)变量。它的工作原理是因为,他足够聪明,无需将参数作为参数传递给事件对象。

ng-keyup="searchEnter($event)"

<强>代码

$scope.searchEnter = function(e) { //firefox needs event to be taken as parameter
    if( !e ) e = window.event; // <-- its needed for IE
    if(e.which == 13 && $scope.Input != "") {
        $scope.addInput();
    }
};