zoukankan      html  css  js  c++  java
  • 按住CTRL多选,按住shift连选的实现

    <tr class="address" v-for="(counts, index) in counts" :key="index" @click="trSelect(index)" :class="rowsSelect.indexOf(index) != -1 ? 'selectTr' : ''"></tr>
    
    document.onkeydown =  (e) => {
                        if (!this.keyCode) {
                            if (window.event) {
                                this.keyCode = event.keyCode;
                            } else if (e.which) {
                                this.keyCode = e.which;
                            }
    
                        }
                    };
                    document.onkeyup =  () => {
                        if (this.keyCode) {
                            this.keyCode = undefined;
                        }
                    };
    trSelect(index) {
                        switch (this.keyCode) {
                            case 17://ctrl
                                this.isCtrl = true;
                                if (this.rowsSelect.indexOf(index) != -1) {
                                    this.rowsSelect.splice(index, 1);
                                } else {
                                    this.rowsSelect.push(index);
                                }
                                this.startIndex = index;
                                break;
                            case 16://shift
                                if (!this.isCtrl && this.rowsSelect.length == 0) {
                                    this.rowsSelect.push(index);
                                    this.startIndex = index;
                                    return;
                                }
                                let start, end;
                                if (this.startIndex < index) {
                                    start = this. startIndex;
                                    end = index;
                                } else {
                                    start = index;
                                    end = this.startIndex;
                                }
                                this.rowsSelect = [];
    
                                for (let k = start; k <= end; k++) {
                                    this.rowsSelect.push(k);
                                }
                                this.isCtrl = false;
                                break;
                            default:
                                this.rowsSelect = [index];
                                this.isCtrl = false;
                                this.startIndex = index;
                                break;
                        }
    
                    }
    

      

      

  • 相关阅读:
    systemctl
    防火墙firewalld
    k8s 基础概念
    进程
    模板问题
    自动发现
    oracle操作
    aix 10代oracle zabbix2.4.4 日志监控
    paramiko
    test
  • 原文地址:https://www.cnblogs.com/lrxsblog/p/9923456.html
Copyright © 2011-2022 走看看