点击li中的radio,选中li中的文字;
点击li中的文字,选中li中的radio;
<script type="text/javascript"> var app=angular.module('app',[]); app.controller('mainController',['$scope',function($scope){ // $scope.conditions=[ {name:"axxxxx",age:"34"},{name:"bxxxxx",age:"19"},{name:"cxxxxx",age:"25"},{name:"dxxxxx",{name:"exxxxx",{name:"fxxxxx",{name:"gxxxxx",age:"22"},{name:"hxxxxx",{name:"ixxxxx",{name:"jxxxxx",age:"43"},{name:"kxxxxx",age:"28"} ]; $scope.spanRadioChecked=false; //radio $scope.radioClickFun=function(con){ $scope.flag=con; } //span $scope.spanFun=function(con){ $scope.flag=con; } }]); //指令:点击时“选中”、获取值、“背景变色” app.directive('selectOnClick',['$window',function($window) { return { restrict:'A',link: function(scope,element,attrs) { element.on('click',function(){ alert(element.html()); }); } }; }]); </script>
<div ng-controller="mainController"> <ul style="height:110px; border: 1px solid #dddddd;overflow-y: scroll;"> <li ng-repeat="con in conditions" ng-model="flag"> <input type="radio" name="conRadio" ng-click="radioClickFun(con.name)" ng-checked="con.name==flag"/> <span ng-click="spanFun(con.name)" ng-class="{'spanRadioChecked':con.name==flag}">{{con.name}}</span> </li> </ul> </div>原文链接:https://www.f2er.com/angularjs/147548.html