1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>select all</title> 6 <script type="text/javascript" src="../avalon.shim.js" ></script> 7 <script type="text/javascript"> 8 var model=avalon.define({ 9 $id:"test", 10 data:[{checked:false},{checked:false},{checked:false}] 11 }); 12 </script> 13 </head> 14 <body> 15 <table ms-controller="test" border="1"> 16 <tr> 17 <td><input type="checkbox" />全選</td> 18 </tr> 19 <tr ms-repeat="data">//ms-repeat="data"放入須要循環的元素中(這裏須要循環tr,data是vm裏頭定義的屬性,屬性值類型是對象數組,對象是checked:false未被選中的意思) 20 <td><input type="checkbox" />xxxxxxx</td> 21 </tr> 22 </table> 23 </body> 24 </html>
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>select all</title> 6 <script type="text/javascript" src="../avalon.shim.js" ></script> 7 <script type="text/javascript"> 8 var model=avalon.define({ 9 $id:"test", 10 data:[{checked:false},{checked:false},{checked:false}], 11 allchecked:false, 12 checkAll:function(){ 13 var bool = model.allchecked = this.checked; 14 model.data.forEach(function(el){ 15 el.checked = bool; 16 }); 17 } 18 }); 19 </script> 20 </head> 21 <body> 22 <table ms-controller="test" border="1"> 23 <tr> 24 <td><input type="checkbox" ms-duplex-checked="allchecked" data-duplex-changed="checkAll"/>全選</td> 25 </tr> 26 <tr ms-repeat="data"> 27 <td><input type="checkbox" ms-duplex-checked="el.checked"/>xxxxxxx</td> 28 </tr> 29 </table> 30 </body> 31 </html>
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>select all</title> 6 <script type="text/javascript" src="../avalon.shim.js" ></script> 7 <script type="text/javascript"> 8 var model=avalon.define({ 9 $id:"test", 10 data:[{checked:false},{checked:false},{checked:false}], 11 allchecked:false, 12 checkAll:function(){ 13 var bool = model.allchecked = this.checked; 14 model.data.forEach(function(el){ 15 el.checked = bool; 16 }); 17 }, 18 checkOne:function(){ 19 if(!this.checked){ 20 model.allchecked = false; 21 }else{ 22 model.allchecked = model.data.every(function(el){ 23 return el.checked; 24 }); 25 } 26 } 27 }); 28 </script> 29 </head> 30 <body> 31 <table ms-controller="test" border="1"> 32 <tr> 33 <td><input type="checkbox" ms-duplex-checked="allchecked" data-duplex-changed="checkAll"/>全選</td> 34 </tr> 35 <tr ms-repeat="data"> 36 <td><input type="checkbox" ms-duplex-checked="el.checked" data-duplex-changed="checkOne"/>xxxxxxx</td> 37 </tr> 38 </table> 39 </body> 40 </html>