AngularJs 상태 값 을 누 르 면 배경 색 을 바 꾸 는 실례

실례 는 다음 과 같다.

//           $("#shname").css({"border":"1px solid red"});
//                             
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.11.0.min.js" ></script>
<script type="text/javascript" src="js/angular.min.js" ></script>
<style>
*{
margin: 0 auto;
padding: 0;
}
.div{
margin-top: 50px;
width: 800px;
height: 1000px;
}
.tian{
width: 80px;
height: 24px;
background: #5CD6FF;
}
#sp{
width: 150px;
height: 24px;
margin-left: 130px;
border-radius: 10px;
}
#sj{
height: 24px;
margin-left: 20px;
border-radius: 10px;
}
#st{
height: 24px;
margin-left: 30px;
}
#t{
width: 14px;
height: 14px;
position: absolute;
margin-left: -24px;
padding-top: 6px;
}
#t1{
width: 14px;
height: 14px;
position: absolute;
margin-left: -24px;
padding-top: 6px;
}
#table{
margin-top: 50px;
}
.fh1{
background: #FCFC30;
}
.true {
background: greenyellow;
border: 0px;
border-radius: 3px;
}
.false {
background: yellow;
border: 0px;
border-radius: 3px;
}
</style>
</head>
<body ng-app="myapp" ng-controller="mycr">
<div class="div">
<input type="button" value="    " ng-click="add()" class="tian"/>
<input type="button" value="    " ng-click="px()" class="tian"/>
<input type="text" placeholder="       " id="sp" ng-model="msname"/>
<img src="img/q.png" id="t" ng-click="nameselect()"/>
<input type="text" placeholder="      " id="sj" ng-model="mytel"/>
<img src="img/q.png" id="t1" ng-click="sjselect()"/>
<select id="st" ng-change="myfh()" ng-model="fh" ng-init="fh=cha[0]">
<option ng-repeat="c in cha">{{c}}</option>
</select>
<table border="1px" cellspacing="1" cellpadding=""0 width="800px" height="30px" id="table">
<tr align="center">
<td><input type="checkbox" ng-model="qx" ng-click="myqx()"/></td>
<td>id&nbsp;&nbsp;<input type="button" value="  " ng-click="idp()"/></td>
<td>   </td>
<td>   </td>
<td>   </td>
<td>  &nbsp;&nbsp;<input type="button" value="  " ng-click="jiap()"/></td>
<td>  </td>
<td>    &nbsp;&nbsp;<input type="button" value="  " ng-click="ship()"/></td>
<td>  </td>
</tr>
<tr align="center" ng-repeat="x in user|filter:{sname:sn}|filter:{tel:sh}|filter:fahuo|orderBy:idpai">
<td><input type="checkbox" ng-model="x.flog" ng-click="dx($index)"/></td>
<td>{{x.id}}</td>
<td>{{x.sname}}</td>
<td>{{x.name}}</td>
<td>{{x.tel}}</td>
<td>{{x.price|currency:"¥:"}}</td>
<td>{{x.cheng}}</td>
<td>{{x.time|date:"MM-dd HH:mm:ss"}}</td>
<td><input type="button" value="{{x.zhuang|myFilter}}" class="{{x.zhuang}}" ng-click="fahuo1($index)" /></td>
</tr>
</table>
<fieldset ng-show="yc">
<legend>      </legend>
<center>
   <input type="text" ng-model="shname" id="shname"/>
<span id="s1"></span><br /><br />
   <input type="text" ng-model="username" id="username"/>
<span id="s2"></span><br /><br />
   <input type="text" ng-model="mtel" id="mtel"/>
<span id="s3"></span><br /><br />
   <input type="text" ng-model="mprice" id="mprice" />
<span id="s4"></span><br /><br />
     <select ng-model="chengshi" ng-init="chengshi=cs[0]" ng-change="xuancs()" style="width: 140px;">
<option ng-repeat="xx in cs">{{xx}}</option>
</select>
<span id="s5" ></span><br /><br />
<input type="button" value="  " ng-click="baocun()"/>
</center>
</fieldset>
</div>
</body>
<script>
var app=angular.module("myapp",[]);
app.controller("mycr",function($scope){
//select    
$scope.cha=["     ","   ","   "];
$scope.cs=["     ","  ","  ","  ","  "];
$scope.user=[{
"flog":false,
"id":2001,
"sname":"IphoneX",
"name":"  ",
"tel":"13525654123",
"price":"8699",
"cheng":"  ",
"time":"14560161945000",
"zhuang":false,
},
{
"flog":false,
"id":3006,
"sname":"Iphone6",
"name":"  ",
"tel":"12564236541",
"price":"5635",
"cheng":"  ",
"time":"1456016212945000",
"zhuang":false,
},
{
"flog":false,
"id":5312,
"sname":"Iphone7",
"name":"   ",
"tel":"13402651245",
"price":"6180",
"cheng":"  ",
"time":"666016215645000",
"zhuang":false,
},
{
"flog":false,
"id":2314,
"sname":"Iphone8",
"name":"  ",
"tel":"17695212525",
"price":"7190",
"cheng":"  ",
"time":"88888162545000",
"zhuang":false,
}
];
  

//        
$scope.nameselect=function(){
$scope.sn=$scope.msname;
//        
$scope.sh="";
}
//       
$scope.sjselect=function(){
$scope.sh=$scope.mytel;
//       
$scope.sn="";
}
//            
$scope.myfh=function(){
if($scope.fh=="     "){
$scope.fahuo="";
}else if($scope.fh=="   "){
$scope.fahuo=true;
$scope.sn="";
$scope.sh="";
}else{
$scope.fahuo=false;
$scope.sn="";
   $scope.sh="";
     
}
}
//  
$scope.myqx=function(){
if($scope.qx){
for (var i=0;i<$scope.user.length;i++) {
$scope.user[i].flog=true;
}
}else{
for (var i=0;i<$scope.user.length;i++) {
$scope.user[i].flog=false;
} 
}
}
//           
$scope.dx=function($index){
if($scope.user[$index].flog==false)
$scope.qx=false;
}
//    
$scope.px=function(){
var j=0;
for (var i=0;i<$scope.user.length;i++) {
if($scope.user[i].flog){
j++;
}
}
if(j==0){
alert("       ")
}

//                              
var flog1=true;
for (var i=0;i<$scope.user.length;i++) {
if($scope.user[i].flog){
if($scope.user[i].zhuang==false)
flog1=false;
}
} 

if(flog1){
for (var i=$scope.user.length-1;i>=0;i--) {
if($scope.user[i].flog){
$scope.user.splice(i,1);
//         false
$scope.qx=false;
}
}
}else{
alert("        ")
}
}
//  id     
var c=0;
$scope.idp=function(){
c++;
 if(c%2==1){
 $scope.idpai='id';
  
 }else{
 $scope.idpai='-id';
 
 }
}
//         
$scope.jiap=function(){
c++;
 if(c%2==1){
 $scope.idpai='price';
  
 }else{
 $scope.idpai='-price';
 
 }
}
//      
$scope.ship=function(){
c++;
 if(c%2==1){
 $scope.idpai='time';
  
 }else{
 $scope.idpai='-time';
 
 }
}

//          
$scope.add=function(){
$scope.yc=true;
}
//     
$scope.baocun=function(){
flog= kong($("#shname").val(),"#s1")
&&kong($("#username").val(),"#s2")
&&kong($("#mtel").val(),"#s3")
&&kong($("#mprice").val(),"#s4")&&cheng();
if(flog){
var tian={
"flog":false,
"id":"23236",
"sname":$scope.shname,
"name":$scope.username,
"tel":$scope.mtel,
"price":$scope.mprice,
"cheng":$scope.chengshi,
"time":"14560201945000",
"zhuang":false,
}
//      
$scope.user.push(tian);
//       
$scope.shname="";
$scope.username="";
$scope.mtel="";
$scope.mprice="";
//     
$scope.yc=false;
}
}

//      
function kong(k1,s){
var k=/^\s*$/;
if(k.test(k1)){
$(s).html("    ");
return false;
}else{
$(s).html("");
return true;
}
}
//    
function cheng(){
if($scope.chengshi=="     "){
$("#s5").html("  ");
return false;
}else{
$("#s5").html("");
return true;
}
}
/*x.zhang            false                     
<td><input type="button" value="{{x.zhuang|myFilter}}" class="{{x.zhuang}}" ng-click="fahuo1($index)" /></td>
//           
.true {
background: greenyellow;
border: 0px;
border-radius: 3px;
}
.false {
background: yellow;
border: 0px;
border-radius: 3px;
}
*/
//        
   
$scope.fahuo1 = function($index) {
if($scope.user[$index].zhuang ){
$scope.user[$index].zhuang = false;
}else{
$scope.user[$index].zhuang = true;
}
}
})


//      ,  zhuang   ,      
app.filter("myFilter", function() {

return function(input) {
if (input) {
return "   ";
} else {
return "   ";
}
return input;
}

})
</script>
</html>
이상 의 AngularJs 가 상태 값 을 클릭 하여 배경 색 을 바 꾸 는 인 스 턴 스 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.참고 할 수 있 고 많은 응원 부 탁 드 리 겠 습 니 다.

좋은 웹페이지 즐겨찾기