angularjs用回车键动态添加数据,同时渲染到页面
<script src="../../angular-1.5.5/angular.min.js"></script>
<script>
var myapp=angular.module("myapp",[]);
myapp.controller("myCtrl",function($scope){
$scope.items=[];
$scope.fun=function(event){
console.log(event);
if(event.keyCode==13){//判断键值回车键触发input渲染到ul的li中
$scope.items.unshift($scope.course);回车键触发input渲染到ul的li中
$scope.course="";
}
}
})
</script>
样式
<body ng-app="myapp" ng-controller="myCtrl" ng-keyup="fun($event)"> <input type="text" ng-model="course"> <ul> <li ng-repeat="item in items">{{item}}</li> </ul> </body>

浙公网安备 33010602011771号