Vue.js checkbox 練習
阿新 • • 發佈:2017-09-12
練習 java method div bsp false methods click vue.js
<div id="app"> <input type="checkbox" v-model="sex" value="1" />足球 <input type="checkbox" v-model="sex" value="2" />籃球 <input type="checkbox" v-model="sex" value="3" />乒乓球 <br /> {{sex}} <br /> <button v-on:click="clickall(true)">全選</button> <button v-on:click="clickall(false)">取消全選</button> </div> <script type="text/javascript"> var vm = new Vue({ el: "#app", data: { sex:[] } , methods: { clickall: function (flag) { if (flag) { _this= this; this.sex = []; $.each($(":checkbox"), function (i, v) { _this.sex.push(v.value); }); } else { this.sex = []; } } } }); </script>
Vue.js checkbox 練習