http://blog.csdn.net/amohan/article/details/39249369
场景:给多个按钮绑定事件,并得到点击对象。
在最上面的元素加上点击事件,然后利用$event.target得到点击对象
看代码
<ul class="result-choose" id="ResultChoose" ng-click="changeStatus($event);">
<li id="Success">
<!--<span ng-class="{true: 'checked'}[isActive]">拨打成功</span>-->
<span ng-class='{checked:tar=="拨打成功"}'>拨打成功</span>
</li>
<li>
<span ng-class='{checked:tar=="占线"}'>占线</span>
</li>
<li>
<span ng-class='{checked:tar=="拒接"}'>拒接</span>
</li>
<li>
<span ng-class='{checked:tar=="号码废弃"}'>号码废弃</span>
</li>
<li>
<span ng-class='{checked:tar=="无人接听"}'>无人接听</span>
</li>
<li>
<span ng-class='{checked:tar=="停机"}'>停机</span>
</li>
<li>
<span ng-class='{checked:tar=="关机"}'>关机</span>
</li>
<li>
<span ng-class='{checked:tar=="号码错误"}'>号码错误</span>
</li>
</ul>
$scope.changeStatus=function($event){
var test=$event.target.childNodes[0].nodeValue;
$scope.tar=test;
if(test!="拨打成功"){
$scope.isActive=true;
}else{
$scope.isActive=false;
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="lib/jquery/jquery-1.10.2.min.js"></script>
<script src="lib/angular/angular.min.js"></script>
</head>
<body ng-app>
<div ng-controller="TestCtrl">
<a href data="1" ng-click="GoPage($event.target)">1</a>
<a href data="2" ng-click="GoPage($event.target)">2</a>
<a href data="3" ng-click="GoPage($event.target)">3</a>
<a href data="4" ng-click="GoPage($event.target)">4</a>
<a href data="5" ng-click="GoPage($event.target)">5</a>
{{ page }}
</div>
<script>
function TestCtrl($scope) {
$scope.page = 1;
$scope.getData = function () {
console.log($scope.page);
}
$scope.GoPage = function (target) {
$scope.page = target.getAttribute('data');
this.getData();
}
}
</script>
</body>
</html>
话题2:angular.element()用法
在Control中,angular.element()返回一个jquery对象,如angular.element(document).ready(function(){});
所以你可以对她做你对所有jquery对象可以做的事
返回指定元素的scope:var sidebar = document.getElementsById(‘sidebar’); var scope = angular.element(sidebar).scope();