2016-08-24 105 views
1

我已經在angularJS中編寫基本代碼來打印用戶輸入。它的工作在鉻,但不是在Firefox。附加html和js文件。任何人都可以請幫我解決這個問題。Firefox瀏覽器問題

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

在Firefox中輸入值不打印頁面。

回答

0

您尚未將event對象傳遞給函數。您應該通過$event(事件對象)變量,同時調用searchEnter方法。它在chrome中工作,因爲他足夠聰明,無需將它作爲參數傳遞即可獲取事件對象。

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(); 
    } 
}; 
+0

謝謝潘卡。它的工作很好 – Jayasree

+0

@Jayasree很高興聽到這個消息,請接受答案,以便它也能幫助其他人。謝謝 :-) –