<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body ng-app="myApp" ng-controller="myCon">
<input type="text" ng-keydown="add($event)" ng-model="name" />
<ul>
<li ng-repeat="x in names">{{ x }}</li>
</ul>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller("myCon",function($scope){
$scope.names=["张三","思思"];
$scope.add= function($event){
var newName=[];
var code = $event.keyCode;
if(code==13){
console.log("回车");
var n = $scope.name;
for (var i = 0; i <$scope. names.length; i++) {
var n1 = $scope.names[i];
if (n==n1) {
alert("存在了");
return;
}
}
$scope.names.unshift(n);
}
};
});
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body ng-app="myApp" ng-controller="myCon">
<input type="text" ng-keydown="add($event)" ng-model="name" />
<ul>
<li ng-repeat="x in names">{{ x }}</li>
</ul>
<script type="text/javascript">
var app = angular.module("myApp",[]);
app.controller("myCon",function($scope){
$scope.names=["张三","思思"];
$scope.add= function($event){
var newName=[];
var code = $event.keyCode;
if(code==13){
console.log("回车");
var n = $scope.name;
for (var i = 0; i <$scope. names.length; i++) {
var n1 = $scope.names[i];
if (n==n1) {
alert("存在了");
return;
}
}
$scope.names.unshift(n);
}
};
});
</script>
</body>
</html>