分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

AngularJS 启程三

发布时间:2023-09-06 01:55责任编辑:沈小雨关键词:AngularAngularJS
<!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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved