zoukankan      html  css  js  c++  java
  • vue day7 table checkbox 全选

     
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>分页</title>
            <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
        <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    
    </head>
    <body>
    
        <div id="app-4" class="col-xs-12 main-table-wrapper">
            <table class="table table-striped table-hover table-bordered" id="main-table">
                <thead>
                    <tr>
                        <th><input type="checkbox" v-model="checkall"  v-on:click='checkAll'></th>
                        <th>商品名称</th>
                        <th>商品单价</th>
                        <th>数量</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in tableData">
                        <td><input type="checkbox" v-model="checked" :value="item.id"  />   </td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.address }}</td>
                        <td>{{ item.date }}</td>
                        <td><button @click="handleRemove(index)">移除</button></td>
    
                    </tr>
    
    
                </tbody>
            </table>
            <div>{{checked}}</div>
        </div>  
    
    
        
        <script>
    
    
    
    
    
            var app = new Vue({
                el: '#app-4',
                data: {
                    tableData: [{
                        id:1,
                        date: '2016-05-02',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1518 弄',
    
                        }, {
                            id:2,
                            date: '2016-05-04',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1517 弄'
                        }, {
                            id:3,
                            date: '2016-05-01',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1519 弄'
                        }, {
                            id:4,
                            date: '2016-05-03',
                            name: '王小虎',
                            address: '上海市普陀区金沙江路 1516 弄'
                        }
                    ],
                    checkall:false,
                    checked:[]
                },
                methods: {
                    handleRemove: function(index){
                            this.tableData.splice(index,1);
                        },
                    checkAll: function () {
                        var _this = this
                        if (this.checkall) {
                        // 实现反选
                            this.checked = []
                        } else {
                        // 实现全选
                            this.checked = []
                            this.tableData.forEach(function (item) {
                                _this.checked.push(item.id)
                            })
                        }
                        if (this.checked.length === this.tableData.length) {
                            this.checkall = true
                        // console.log(this.checkall)
                        // console.log(this.checked)
                        } 
                    }
                }
            });
    
    
     
    
        </script>
    </body>
    </html>
  • 相关阅读:
    使用Apache Benchmark做压力测试遇上的5个常见问题
    性能测试框架Multi-Mechanize安装与使用
    jmeter ---监控服务器CPU, 内存,网络数据
    在free bsd上跑JMeter 的 plugin "PerfMon Server Agent"
    解决Jmeter插件ERROR: java.io.IOException: Agent is unreachable via TCP的错误
    JMeter
    Freebsd的ports命令
    转 FreeBSD通过PORTS安装软件的几个常用命令
    spring cloud 中Actuator不显示更多信息的处理方式
    ISAM Indexed Sequential Access Method 索引顺序存取方法
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/10657451.html
Copyright © 2011-2022 走看看