zoukankan      html  css  js  c++  java
  • 判断相同的不允许添加JS

    首先新建个全局的数组

    clientIdArr: [],

    然后点击添加的时候判断

     addCompany: function(oli) {
            var a = oli.innerText, //客户名称
                b = oli.getAttribute('data-name'), //等级名称
                c = oli.getAttribute('data-info'), //等级ID
                f = oli.getAttribute('data-new-discount'), //新折扣
                g = oli.getAttribute('data-once-amount'), //起订量
                h = oli.getAttribute('data-can-buy'), //是否允许购买 (0不允许/1允许)
                d = $(oli).children('span')[0].attributes['data-name'].value, //客户默认折扣
                e = $(oli).children('span')[0].attributes['data-info'].value; //客户ID
            // ------------------------------------
            // console.log(_this.clientIdArr);
            // console.log('----------------' + typeof _this.clientIdArr); //object
            if (_this.clientIdArr.length > 0) {
                // console.log('--------1--------')
                for (var i = 0; i < _this.clientIdArr.length; i++) {
                    // console.log('--------循环--------')
                    console.log(_this.clientIdArr[i]);
                    if (_this.clientIdArr[i] == e) {
                        layer.msg('此客户已经添加过!')
                            // console.log('--------有相同的存在--------');
                        return false;
                    }
                }
                // console.log('--------5--------')
                $('#c-table tbody').append(_this.addTr(a, b, c, d, e, f, g, h));
                _this.clientIdArr.push(e);
                $(oli).remove();
    
            } else {
                // console.log('--------2--------')
                $('#c-table tbody').append(_this.addTr(a, b, c, d, e, f, g, h));
                _this.clientIdArr.push(e);
                $(oli).remove();
            }
        },

    下面是删除后把数组里面的ID也删除

     delCompany: function(tr) {
            var a = $(tr).parents('tr').find('td').eq(1).text(), //客户名称
                b = $(tr).parents('tr').find('td').eq(3).text(); //等级名称
            c = $(tr).parents('tr').find('td').eq(3)[0].attributes['data-info'].value; //等级ID
            d = $(tr).parents('tr').find('td').eq(4).text(); //客户默认折扣
            //alert(d);return false;
            e = $(tr).parents('tr').find('td').eq(1)[0].attributes['data-info'].value; //客户ID
            f = $(tr).parents('tr').find('td').eq(1)[0].attributes['data-new-discount'].value; //新折扣
            g = $(tr).parents('tr').find('td').eq(1)[0].attributes['data-once-amount'].value; //起订量
            h = $(tr).parents('tr').find('td').eq(1)[0].attributes['data-can-buy'].value; //是否允许购买
    
            $('.customeList').append(_this.oli(a, b, c, d, e, f, g, h));
            for (var i = 0; i < _this.clientIdArr.length; i++) { //删除数组里的ID
                if (_this.clientIdArr[i] == e) {
                    _this.clientIdArr.splice(i, 1);
                    break;
                }
            }
            $(tr).parents('tr').remove();
            if ($('#c-table tbody').find('tr').length == 0) {
                // $('#rowHiden').hide();
                $('input[name=custome]').attr("checked", false);
            }
        },
  • 相关阅读:
    缺失的第一个正数
    tuple用法
    整数转罗马数字
    三种时间格式的转换
    不同包的调用
    正则表达式
    lgb模板
    线性回归
    时间序列的特征
    3D聚类
  • 原文地址:https://www.cnblogs.com/hasubasora/p/6952710.html
Copyright © 2011-2022 走看看