<div ng-app="myApp" ng-controller="myCtrl">
<h2>博客记录</h2>
<textarea ng-model="message" cols="40" rows="10"></textarea>
<p>
<button ng-click="save()">报错</button>
<button ng-click="clear()">清除</button>
</p>
<!-- 绑定 -->
<p>剩余字数:<span ng-bind="left()"></span></p>
<script>
var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
// 设置框中内容为空
$scope.message = "";
// 数字剩余绑定,与输入框内容长短关联
$scope.left = function(){
// 设置还能输入多少字
return 100 - $scope.message.length;
};
// 清除按钮
$scope.clear = function(){
$scope.message = "";
};
$scope.save = function(){
alert('Note Sved');
}
})
</script>
</div>
angularJS-----模拟博客输入框
最新推荐文章于 2022-05-23 11:50:08 发布