zoukankan      html  css  js  c++  java
  • angular 最大字数限制

    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

  • 相关阅读:
    OSCache报错error while trying to flush writer
    html 输入框验证
    Struts2 一张图片引发的bug
    Html 小插件10 即时新闻
    String
    内部类
    多态
    抽象&接口
    继承
    封装
  • 原文地址:https://www.cnblogs.com/xulei1992/p/9933656.html
Copyright © 2011-2022 走看看