Javascript innerHtml重复

时间:2016-07-06 02:43:38

标签: javascript

我正在编写innerHtml,但div一次又一次地重复着。我不知道如何解决。谢谢你的帮助。

我的代码如下:

for(b=0; b<Object.keys(getCurrentAM).length; b++){

    var num = Object.keys(getCurrentAM)[b];
    var dutyData = getCurrentAM[num];

    var res = num.replace("A", "P");
    var newD2 = num.replace("A", "");

    var amDuty = document.getElementById('' + num + '_amDuty');
    var locationDuty = document.getElementById('' + num + '_locationDuty');
    var pmDuty = document.getElementById('' + res + '_pmDuty');

    amDuty.style.display = 'block';
    locationDuty.style.display = 'block';
    pmDuty.style.display = 'block';

    if ((amDuty.getElementsByTagName('na').length == 0) && (locationDuty.getElementsByTagName('na').length == 0) && (pmDuty.getElementsByTagName('na').length == 0) ){          

        amDuty.innerHTML = '<div class="dutyChangeSize">'+ amDuty.innerHTML + '<br/>' + locationDuty.innerHTML + '<br/>' + pmDuty.innerHTML + '</div>';
        locationDuty.innerHTML = '';
        pmDuty.innerHTML = '';
    }
}

1 个答案:

答案 0 :(得分:0)

我改变了课程,并使用css不显示重复。

for(b=0; b<Object.keys(getCurrentAM).length; b++){

var num = Object.keys(getCurrentAM)[b];
var dutyData = getCurrentAM[num];

var res = num.replace("A", "P");
var newD2 = num.replace("A", "");

var amDuty = document.getElementById('' + num + '_amDuty');
var locationDuty = document.getElementById('' + num + '_locationDuty');
var pmDuty = document.getElementById('' + res + '_pmDuty');

amDuty.style.display = 'block';
locationDuty.style.display = 'block';
pmDuty.style.display = 'block';

if ((amDuty.getElementsByTagName('na').length == 0) && (locationDuty.getElementsByTagName('na').length == 0) && (pmDuty.getElementsByTagName('na').length == 0) ){          

   amDuty.className = "dutyChangeSize";

   amDuty.innerHTML = ''+ amDuty.innerHTML + '<br/>' + locationDuty.innerHTML + '<br/>' + pmDuty.innerHTML + '';
   locationDuty.innerHTML = '';
   pmDuty.innerHTML = '';
}
    }

- &GT; CSS

br + br {display:none}