【发布时间】:2016-02-29 14:26:26
【问题描述】:
谁能帮帮我。我对逻辑 Angularjs 应用程序 Typing Tutor 有点困惑。我想要一个关于如何测试来自文本框的用户输入并用红色显示错误的逻辑。像这样……
我希望当用户在文本框中输入文本时,这些文本应该与数组名称 typingData 的数据匹配。
如果两个元素都不匹配,则显示文本的红色背景色............ 好像有一个我想要的例子......
http://crazy2be.github.io/dvorak-typing-tutor/
enter code here
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<style>
p{
margin-left: 200px;
width: 500px;
height: 200px;
border : 2px dashed red;
background-color: lightblue;
border-collapse: collapse;
}
#inputText{
width: 500px;
height: 50px auto;
}
</style>
</head>
<body ng-controller="myController">
<div>
<div>
<p>
<span ng-repeat="x in typingData">  {{x}}
</span>
</p>
<div style="margin-left: 200px;">
<input type="text" ng-model="inputText" ng-keydown="test()" id="inputText" >
</div>
</div>
</div>
<script>
var app= angular.module('myApp',[]);
app.controller('myController',function($scope) {
$scope.typingData=['tl','sg','re','wf',' kr','up' //'few','above','water','answer','cut','look','out','begin','paper'
];
$scope.getData = [];
$scope.checkText = function(){
for(i=0;i<$scope.typingData.length;i++){
//console.log($scope.typingData[i].split(""));
}
}
$scope.test = function(){
$scope.getData.push($scope.inputText);
console.log($scope.getData);
}
/*$scope.$watch('inputText',function(newValue,oldValue){
if(newValue !== oldValue){
console.log(newValue);
//console.log($scope.inputText);
}
});*/
});
【问题讨论】:
标签: javascript angularjs