console.log(event.target.checked)
例:
例:
实现:选中按钮激活,不选 input 加上disabled
方法一:@click方法:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="app"> <label for="ab1"><input type="checkbox" id="ab1" @click = "checkbox()">我同意</label><br/> <button type ="button" :disabled = "!dis">注册</button> </div> </body> <script src="js/vue2.js"></script> <script type="text/javascript"> var vm = new Vue({ el:'#app', data:{ dis:false }, methods:{ // 选中为true,未选中为false checkbox(){ this.dis = event.target.checked console.log(event.target.checked) } } }) </script> </html>
方法二: v-model ,v-model =“dis”的值就是checked 是否选中的值 等同于 event.target.checked
<div id="app"> <label for="ab2"><input type="checkbox" id="ab2" v-model="dis">我同意 {{dis}}</label><br/> <button type ="button" :disabled = "!dis">注册</button> </div> var vm = new Vue({ el:'#app', data:{ dis:false }, methods:{ } })