http://www.cnblogs.com/liubaichi/p/6051490.html <!DOCTYPE html><html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="angular-1.5.8.js"></script> </head> <body> <div ng-app ng-init="num=2"> <div ng-switch="num"> <div ng-switch-when="0">00</div> <div ng-switch-when="1">11</div> <div ng-switch-when="2">22</div> <div ng-switch-default>333</div> </div> </div> <script> //在angular中的ng-switch方法的使用,先要綁定一變量;再分情況來是執(zhí)行,當(dāng)時(shí)變量的值是什么情況的(ng-swtich-when="變量的值"); //那么當(dāng)都不滿足的時(shí)候(ng-switch-default); // 下面的js中的switch/case的使用;要進(jìn)行類比 </script> <script> var data=1; switch (data){ case(0): alert("00"); break ; case(1):alert("11"); break; default :alert("222"); } </script> </body> </html> |
|