Angular JS做一个字数限制和提示
发布时间:2020-12-17 09:33:19 所属栏目:安全 来源:网络整理
导读:HTML na-app:指定当前层级及以下层级属于AngularJS应用 na-controller:指定controller名字,和JS代码中的controller名字做绑定 ng-model:html中指定属性值,并把这个属性值和控件的value做绑定 div class = "span12 field-box textarea" ng-app = "myApp" ng-c
<div class="span12 field-box textarea" ng-app="myApp" ng-controller="myCtrl">
<label>备注:</label>
<textarea class="span9" ng-model="name"></textarea>
<span class="charactersleft">已经输入{{length}}个字符总共可以输入100个字符</span>
</div>
/*以下是我添加的数据*/
/*监听文本框内容的变化*/
$(function () {
var app = angular.module("myApp",[]);
app.controller("myCtrl",function ($scope) {
$scope.length = 0;
$scope.$watch('name',function (newValue,oldValue,scope) {
$scope.length = newValue.length;
if ($scope.length > 100) {
$scope.name = oldValue;
}
});
});
})
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 为什么scala的模式加工在类型匹配的for循环中不起
- twitter-bootstrap – Lesscss> bootstrap的dark
- bash – Laravel安装:如何在你的PATH中放置?/ .
- Swift Vapor 3 PostgreSQL Docker-撰写正确的配置
- 《数据结构》第四章 字符串和多维数组 实验
- 使用Docker运行Microsoft SQL Server 2017的方法
- Bootstrap3基础 dropdown divider 下拉列表中的分
- 解决yum命令失效,vim: command not found
- shell的简单批量curl接口脚本
- BootStrap3 后台管理模板放送
热点阅读