还是先从栗子们看起~
如果我想实现这样一个功能,当一个input失去光标焦点时(blur),执行一些语句,比如当输入用户名后,向后台发ajax请求查询用户名是否已经存在,好有及时的页面相应。
输入hellobug
代码如下:
HTML 1 2 3 4 5 6 |
<body ng-controller="MainCtrl"> <lable>用户名: <input type="text" ng-model="username" ng-blur="checkUsername()" /> <span style="color:red;" ng-show="usernameAlreadyExist">用户名已经存在</span> </lable> </body> |
app.controller('MainCtrl', function($scope) { $scope.checkUsername = function() { //send ajax to check on server if (username === 'hellobug') { usernameAlreadyExist = true; } } }); directive('ngBlur',0)!important">$document) { return { link: scope, element,0)!important">attrs) { $(element).bind('blur',0)!important">e){ scope.$apply(attrs.ngBlur); }); } } }) |
@H_404_100@
return ngBlur); }); }; }) |
@H_404_100@
<ul repeater="20"<li>哈哈哈哈</li> </ul> |
@H_404_100@
'repeater',0)!important">restrict: 'A', compile: attrs) { var template = children().clone(); for(i=0; i<repeater - 1; i++) { append(template.clone()); } } } }); |
@H_404_100@