我寫了一個函數,可以在多個表中搜索設備和地圖。一旦找到正確的單元格,它就會將innerHTML返回到頁面頂部的div。在Internet Explorer中的Javascript問題
該功能在Firefox中完美運行,但它在Internet Explorer中不起作用。該函數仍在IE中運行,但它沒有從表中找到它正在查找的內容。
下面是函數:
// Function for searching tables for specific map/device combination.
function findMap(map, device)
{
var flag = false; // to check if the map has been found yet
// Add <strong> tags to map string so it is easier to search for
var mapstring = "<strong>" + map;
// create array of tables
var tables = document.getElementsByTagName('table');
for (var t = 2; t < tables.length; t++)
{
// create array of rows
var tablerows = tables[t].getElementsByTagName("tr");
for (var r = 2; r < tablerows.length; r++)
{
currentRow = tablerows[r];
// Check if current row contains map name
if (currentRow.innerHTML.match(mapstring))
{
var tablecells = currentRow.getElementsByTagName("td");
for (var c = 1; c < tablecells.length; c++)
{
currentCell = tablecells[c];
// Check if current cell contains device name
if (currentCell.innerHTML.match(device))
{
document.getElementById("boxy2").innerHTML = currentCell.innerHTML;
flag = true;
}
if (flag == true) return;
}
if (flag == true) return;
// search for x20 if 920 was not found etc
if (device == "910")
device = "x10";
else if (device == "920")
device = "x20";
else if (device == "930")
device = "x30";
else if (device == "940")
device = "x40";
else if (device == "950")
device = "x50";
// search cells again
for (var c = 1; c < tablecells.length; c++)
{
currentCell = tablecells[c];
if (currentCell.innerHTML.match(device))
{
document.getElementById("boxy2").innerHTML = currentCell.innerHTML;
flag = true;
}
if (flag == true) return;
}
if (flag == true) return;
}
if (flag == true) return; else { document.getElementById("boxy2").innerHTML="Map not available on this device."; }
}
}
}
這件事的任何幫助,將不勝感激。
謝謝。
答案在標題中;) – powtac 2011-02-14 14:07:00
將一些alert()語句放到循環中,顯示關鍵信息以幫助您跟蹤數據並找到問題。 – 2011-02-14 14:15:31
或者試試IE開發工具中的調試器 – David 2011-02-14 14:31:12