<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="angular.js"></script>
<script>
var app = angular.module("myApp",[]);
app.filter("myFilter",function () {
return function (text) {
if (text.indexOf("a")>=0){
alert("敏感字符");
return text.replace(/a/g,"*");
}
return text;
}
})
app.controller("myCtrl",function ($scope) {
$scope.newRecord="";
$scope.selectRecord="";
$scope.records = ["早晨花了5块钱吃早饭","中午花了20块钱吃午饭"];
$scope.addRecord = function () {
if ($scope.newRecord=="" || $scope.newRecord==null){
alert("输入内容为空");
}else{
$scope.records.unshift($scope.newRecord);
}
}
var flag = true;
$scope.shousuo = function () {
for (record in $scope.records){
if ($scope.records[record] == $scope.selectRecord){
alert("已存在");
flag = false;
}
}
if (flag){
alert("不存在");
}
}
})
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>记账本</h3>
<div style="width: 300px; height: 250px; border: solid; background-color: beige">
<p ng-repeat="record in records">{{record | myFilter}}</p>
</div>
<br><br>
输入框:<input type="text" ng-model="newRecord"><br><br>
<button ng-click="addRecord()">记录</button>
<br><br>
搜索框:<input type="text" ng-model="selectRecord">
<br><br>
<button ng-click="shousuo()">搜索</button>
</center>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="angular.js"></script>
<script>
var app = angular.module("myApp",[]);
app.filter("myFilter",function () {
return function (text) {
if (text.indexOf("a")>=0){
alert("敏感字符");
return text.replace(/a/g,"*");
}
return text;
}
})
app.controller("myCtrl",function ($scope) {
$scope.newRecord="";
$scope.selectRecord="";
$scope.records = ["早晨花了5块钱吃早饭","中午花了20块钱吃午饭"];
$scope.addRecord = function () {
if ($scope.newRecord=="" || $scope.newRecord==null){
alert("输入内容为空");
}else{
$scope.records.unshift($scope.newRecord);
}
}
var flag = true;
$scope.shousuo = function () {
for (record in $scope.records){
if ($scope.records[record] == $scope.selectRecord){
alert("已存在");
flag = false;
}
}
if (flag){
alert("不存在");
}
}
})
</script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<center>
<h3>记账本</h3>
<div style="width: 300px; height: 250px; border: solid; background-color: beige">
<p ng-repeat="record in records">{{record | myFilter}}</p>
</div>
<br><br>
输入框:<input type="text" ng-model="newRecord"><br><br>
<button ng-click="addRecord()">记录</button>
<br><br>
搜索框:<input type="text" ng-model="selectRecord">
<br><br>
<button ng-click="shousuo()">搜索</button>
</center>
</body>
</html>