您的位置:首页 > Web前端 > AngularJS

angularjs自定义过滤器手机号加星

2018-03-19 08:56 447 查看
本代码转自向军老师的angularjs课程
<!DOCTYPE html>
<html lang="en" ng-app="hd">
<head>
<title></title>
<script type="text/javascript" src="js/angular-1.3.0.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<div ng-controller="ctrl">
<table border="1" width="600">
<tr>
<td>编号</td>
<td>姓名</td>
<td>手机号</td>
</tr>
<tr ng-repeat = "(k,v) in data">
<td>{{v.id}}</td>
<td>{{v.name}}</td>
<td>{{v.mobile | truncate:6}}</td>
</tr>
</table>
</div>
<script type="text/javascript">
var m = angular.module('hd',[]);
m.filter('truncate',function(){
return function(mobile,len){
len = len?len:3;
return mobile.substr(0,11-len)+new String('*').repeat(len);
}
});
m.controller('ctrl',['$scope','$http','$filter',function($scope,$http,$filter){
$scope.data = [
{id:1,name:'刘畅',mobile:'13544664646'},
{id:2,name:'王桢',mobile:'13589898989'},
{id:3,name:'梁志勇',mobile:'13588881234'},
{id:4,name:'钱行',mobile:'13598092735'}
];
}]);
</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: