• js 表格合并单元格


    5列  根据需要可添加 或 删除 strOneTemp  strTwoTemp  strThreeTemp  strFourTemp  strFiveTemp 

    //合并单元格 
    this.mergeCellsTable = function(){
    var strOneTemp = null;
    var indexOne = 1
    var objOne={};

    var strTwoTemp = null;
    var indexTwo = 1
    var objTwo={};

    var strThreeTemp = null;
    var indexThree = 1
    var objThree={};

    var strFourTemp = null;
    var indexFour = 1
    var objFour={};

    var strFiveTemp = null;
    var indexFive = 1
    var objFive={};

    var _$tr = $('#table>tbody>tr');  //对应table的ID
    for(var i=0;i<_$tr.length;i++){
    if(i<_$tr.length-1){    //不包括最后一行
    var flagOne = false;
    var flagTwo = false;
    var flagThree = false;
    var flagFour = false;
    var flagFive = false;

    var oneStr = $(_$tr[i]).find("td").eq(0).text();
    if(oneStr==strOneTemp){
    $(objOne).attr("rowspan",indexOne+1);
    flagOne = true;
    indexOne++;
    }else{
    objOne = $(_$tr[i]).find("td").eq(0);
    strOneTemp = oneStr;
    indexOne = 1;
    }

    var twoStr = $(_$tr[i]).find("td").eq(1).text();
    if(twoStr==strTwoTemp){
    $(objTwo).attr("rowspan",indexTwo+1);
    flagTwo = true;
    indexTwo++;
    }else{
    objTwo = $(_$tr[i]).find("td").eq(1);
    strTwoTemp = twoStr;
    indexTwo = 1;
    }

    var threeStr = $(_$tr[i]).find("td").eq(2).text();
    if(threeStr==strThreeTemp){
    $(objThree).attr("rowspan",indexThree+1);
    flagThree = true;
    indexThree++;
    }else{
    objThree = $(_$tr[i]).find("td").eq(2);
    strThreeTemp = threeStr;
    indexThree = 1;
    }

    var fourStr = $(_$tr[i]).find("td").eq(3).text();
    if(fourStr==strFourTemp){
    $(objFour).attr("rowspan",indexFour+1);
    flagFour = true;
    indexFour++;
    }else{
    objFour = $(_$tr[i]).find("td").eq(3);
    strFourTemp = fourStr;
    indexFour = 1;
    }

    var fiveStr = $(_$tr[i]).find("td").eq(4).text();
    if(fiveStr==strFiveTemp){
    $(objFive).attr("rowspan",indexFive+1);
    flagFive = true;
    indexFive++;
    }else{
    objFive = $(_$tr[i]).find("td").eq(4);
    strFiveTemp = fiveStr;
    indexFive = 1;
    }

    if(flagOne){
    $(_$tr[i]).find("td").eq(0).hide();
    }

    if(flagTwo){
    $(_$tr[i]).find("td").eq(1).hide();
    }

    if(flagThree){
    $(_$tr[i]).find("td").eq(2).hide();
    }

    if(flagFour){
    $(_$tr[i]).find("td").eq(3).hide();
    }

    if(flagFive){
    $(_$tr[i]).find("td").eq(4).hide();
    }
    }
    }
    }

  • 相关阅读:
    微信第三方登录,ios第三方登录(没有进行二次封装,直接调用)
    How Do I Declare A Block in Objective-C?
    Android与JS混编(js调用java)
    React-Native做一个文本输入框组件
    如何在程序退出的时候清除activity栈
    React react-ui-tree的使用
    React-Native OpenGL体验二
    React-Native OpenGL体验一
    react-native使用react-art制作SVG动画
    Android画一个随意拖动的圆形
  • 原文地址:https://www.cnblogs.com/ljc1212/p/9150635.html
Copyright © 2020-2023  润新知