<!DOCTYPE html><html lang="zh_CN"> <head> ?<title>字数小例子</title> </head> <body ng-app="noCntAPP"> ?<div ng-controller="noCntCtrl"> ???<h2>我的笔记</h2> ???<textarea cols="30" rows="10" ng-model="txtArea"></textarea> ???????<p><button>读取</button> ???<button>提交</button> ???<button>撤销</button> ????<p>剩余字数: {{getCount()}}</p> ???</p> ?<div> ?<script type="text/javascript" src="./angular.js"></script> ?<script type="text/javascript"> ???angular.module(‘noCntAPP‘,[]) ??????????.controller(‘noCntCtrl‘,[‘$scope‘,function($scope){ ???????????????$scope.txtArea=‘‘; // 初始化文本区域值为空串 ???????????????$scope.getCount=function(){ ??????????????????return 100 - $scope.txtArea.length; ???????????????} ?????????}]); ?</script> </body></html>
<!DOCTYPE html><html lang="zh_CN"> <head> ?<title>字数小例子</title> </head> <body ng-app="noCntAPP"> ?<div ng-controller="noCntCtrl"> ???<h2>我的笔记</h2> ???<textarea cols="30" rows="10" ng-model="txtArea"></textarea> ???????<p><button>读取</button> ???<button>提交</button> ???<button>撤销</button> ????<p>剩余字数: {{getCount()}}</p> ???</p> ?<div> ?<script type="text/javascript" src="./angular.js"></script> ?<script type="text/javascript"> ???angular.module(‘noCntAPP‘,[]) ??????????.controller(‘noCntCtrl‘,[‘$scope‘,function($scope){ ???????????????$scope.txtArea=‘‘; // 初始化文本区域值为空串 ???????????????$scope.getCount=function(){ ??????????????????if($scope.txtArea.length>100){ ??????????????????$scope.txtArea = $scope.txtArea.slice(0,100); // 超过 100 截取前 0-99 个字符 ???????????????} ??????????????????return 100 - $scope.txtArea.length; ???????????????} ?????????}]); ?</script> </body></html>
AngularJS 启程三
原文地址:https://www.cnblogs.com/Frank99/p/9067956.html