angular简单替换

来源:互联网 发布:小丽和小云在计算 编辑:程序博客网 时间:2024/06/05 14:16
    <script type="text/javascript">        var app = angular.module("myApp", []);        app.filter("replace", function() {            return function(text) {                //alert(text.indexOf("敏感字"));                //return text+text.contains("敏感字");                function replaceValue(text) {                    var value = "";                    if(text.indexOf("法轮功")>=0) {                        //alert("111");                        value =  text.replace(/敏感字/g, "***");                        if(value.indexOf("枪")>=0){                            return value.replace(/敏感字/g, "*");                        }else{                            return value;                        }                    }else{                        if(value.indexOf("枪")>=0){                            return text.replace(/敏感字/g, "*");                        }else{                            return text;                        }                    }                }                return replaceValue(text);                //return text.replace(/敏感字|敏感字/g, "***");            }        });        app.controller("myCtrl", function($scope) {            $scope.value = "敏感字";        })    </script></head><body ng-app="myApp" ng-controller="myCtrl">    请输入:<input ng-model="value" />    <p>{{value | replace}}</p></body>
原创粉丝点击