如何比较innerHTML字符串?

时间:2015-02-23 22:07:27

标签: javascript google-maps innerhtml google-fusion-tables

是否有可能获得“fusiontabledata”和“fusiontabledata2”的结果,比较两者并生成第三个“侧边栏”,仅显示重复项?

document.getElementById('sidebar_1').innerHTML = fusiontabledata;
document.getElementById('sidebar_2').innerHTML = fusiontabledata2;

function getData_From(response) {
  FTresponse = response;
  numRows = response.getDataTable().getNumberOfRows();
  numCols = response.getDataTable().getNumberOfColumns();
  fusiontabledata = "<table><tr>";
  fusiontabledata += "</tr><tr>";
  for (i = 0; i < numRows; i++) {
    for (j = 0; j < numCols; j++) {
      fusiontabledata += "<td>" + response.getDataTable().getValue(i, j) + "</td>";
    }
    fusiontabledata += "</tr><tr>";
  }
  fusiontabledata += "</table>"
  document.getElementById('sidebar_1').innerHTML = fusiontabledata;
}

function getData_To(response) {
  FTresponse = response;
  numRows = response.getDataTable().getNumberOfRows();
  numCols = response.getDataTable().getNumberOfColumns();
  fusiontabledata2 = "<table><tr>";
  fusiontabledata2 += "</tr><tr>";
  for (i = 0; i < numRows; i++) {
    for (j = 0; j < numCols; j++) {
      fusiontabledata2 += "<td>" + response.getDataTable().getValue(i, j) + "</td>";
    }
    fusiontabledata2 += "</tr><tr>";
  }
  fusiontabledata2 += "</table>"
  document.getElementById('sidebar_2').innerHTML = fusiontabledata2;
}

1 个答案:

答案 0 :(得分:1)

innerHTML是一个字符串,您可以轻松比较两个字符串。

两个函数的末尾执行此操作,当字符串相等时,将结果添加到第3个侧边栏:

if(document.getElementById('sidebar_1').innerHTML 
    === 
   document.getElementById('sidebar_2').innerHTML){
   document.getElementById('sidebar_3')
    .appendChild(document.getElementById('sidebar1')
                  .firstChild.cloneNode(true));
}