核心提示:angular简单替换代码实现script type=text/var app = angular.module(myApp, []);app.filter(replace, function() {...
angular简单替换代码实现
<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>