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);
            }
        },
  • 相关阅读:
    Axure高保真开关交互效果
    Axure工具栏展开关闭交互效果
    Axure跑马灯交互效果
    for循环实现百钱买百鸡的问题: 公鸡5元一只,母鸡3元一只,小鸡1元3只,100元要买100只鸡?有多少买法?
    git的几种撤销提交方式
    react父子组件之间传值
    pm2 常用命令
    Dva.js 入门级教学文档-2
    Dva.js 入门级教学文档-1
    深入理解call函数
  • 原文地址:https://www.cnblogs.com/hasubasora/p/6952710.html
Copyright © 2011-2022 走看看