1. 程式人生 > >Vue.js checkbox 練習

Vue.js checkbox 練習

練習 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 練習