zoukankan      html  css  js  c++  java
  • vue中如何判断checkbox是否选中

    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:{
           
        }
    })

     

  • 相关阅读:
    vue--一些预设属性
    vue--vux框架的使用
    vue--vConsole
    vue--音乐播放器
    vue--使用vue-cli构建项目
    vue--实例化对象
    vue--数据显示模版上
    CSS--交互效果
    Git SSH公钥配置
    gradle配置国内镜像
  • 原文地址:https://www.cnblogs.com/liubingyjui/p/12844307.html
Copyright © 2011-2022 走看看