我有一个 4-5 行的 div ...当我点击任何一行时,它应该更改选定的行并将其着色为红色,其余全部为黑色...我使用以下逻辑但不适合我给出错误 angular.min.js:117 TypeError: angular.element(...).siblings is not a function
我需要包含 jQuery 文件吗? 我可以不包含 jQuery 文件吗?
求助
$scope.divClick = function($event){
console.log($event.target);
/* below siblings function not working for me*/
angular.element(event.target).siblings().css('color','black');
angular.element(event.target).css('color','red');
};
<div ng-controller="homeController">
<h1>Welcome</h1>
<div ng-repeat="x in json" ng-click="divClick($event)">
Name: {{x.Name}}<br/> City: {{x.City}}<br/> Country: {{x.Country}}<br/><br/>
</div>
</div>
最佳答案
将默认颜色设置为黑色。
<div ng-repeat="x in json" ng-class="{setRed: $index == value}" ng-click="divClick($index)">
为您的类 setRed 提供 CSS 样式。
你的 Controller 函数:
$scope.divClick = function(index){
$scope.value = index;
};
关于angularjs - 我如何在 AngularJS 中选择兄弟元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36886792/