js可以通过onkeyup onkeydown判断当前节点字数。
angular可以通过监听的方式:
$scope.input = {//初始化,避免ng-model绑定取不到值 MaxBT:'', MaxNM:'' } $scope.$watch('input.MaxBT', function(newValue, oldValue) { if ($scope.input.MaxBT.length>15){ alert("网站标题最多为15字"); $scope.input.MaxBT = oldValue; } });
<p>网站标题:<input type="text" class="title" ng-model="input.MaxBT"></p>
也可以设置过滤器:
angular .module('jibao') .filter('CarouselContentFilter',CarouselContentFilter);
function CarouselContentFilter ( ) { return function (str) { if(str){ var carContent = ''; if(str.length >= 50){ str.length = 50; carContent = str.substring(0,50) + '...'; } else { carContent = str } return carContent } } }
<div class="ani title jb_carousel_content"> {{img.configXml.content | CarouselContentFilter}} </div>
参考:https://blog.csdn.net/xuehu837769474/article/details/82109350
https://www.cnblogs.com/wjunwei/p/6491394.html