2014-10-30 228 views
3

首先我需要说的是,我对JS没有太多的经验。目前我试图用MVC框架实现一个Web应用程序。我正在开发一款兼容Internet Explorer的应用程序。在这种情况下,我使用以下JS方法来填充该工作正常与所有的浏览器的表格....调用Array.length时出现未知错误

function populateTable(array) { 
document.getElementById("instalationTable").style.display = "block"; 
var table = document.getElementById("ActivityDescription_installationID"); 
table.innerHTML = ""; 
elementsInTable = array; 
var x = 0; 
for (i = 0; i < (array.length * 2) ; i++) { 
    //alert(i); 
    if ((i % 2) == 0) { 
     //ID Row 

     var row = table.insertRow(i); 

     var cell_1 = row.insertCell(0); 
     cell_1.innerHTML = "<input type='text' disable='' class='form-control' value=" + array[x]  + ">"; 
     x = x + 1; 

     var cell_2 = row.insertCell(1); 
     cell_2.innerHTML = "<span class='btn btn-default' onclick='showEditRow(this)'><img src='../../Content/images/1414409386_48-24.png' /></span>"; 

     var cell_3 = row.insertCell(2); 
     cell_3.innerHTML = "<span class='btn btn-default' onclick='removeRow(this)'>X</apan>"; 
    } 
    else { 
     //Detail Row 
     var rowDetails = table.insertRow(i); 
     var cell = rowDetails.insertCell(0); 
     //cell.colspan = "3"; 
     cell.innerHTML = "<table style='background-color:rgb(98, 98, 98);color:black;border- radius: 5px;' margin:2%; >" + 
      "<tr>" + 
       "<td><input type='checkbox' id='"+x+"_appServer'/> Application Server</span></td>" + 
       "<td>" + 
        "<select id='" + x + "_appServerVersion'>" + 
         "<option>Application version</option>" + 
        "</select>" + 
       "</td>" + 
      "</tr>" + 
      "<tr>" + 
       "<td colspan='2'><input type='radio' name='database' id='"+x+"_emptyDb' onChange='enableOptions(1)'/>" + 
       " Empty Database</br><input type='radio' name='database' id='" + x + "_instalationSlt' onChange='enableOptions(2)'/> Something Databse</td>" + 
      "</tr>" + 

      "<tr id='emptyDB'>" + 
       "<td>" + 
        "Oracle Version"+ 
        "<select id='JS_OraVersion' name='" + x + "_oraVersion' style='width:100%'>" + 
         "<option>Ora version</option>" + 
        "</select>" + 
       "</td>" + 
       "<td>" + 
        "Character Set" + 
        "<select id='JS_ChaSet' name='" + x + "_ChaSet' style='width:100%'>" + 
         "<option>Cha Set</option>" + 
        "</select>" + 
       "</td>" + 
      "</tr>" + 
      "<tr id='dbImport'>" + 
       "<td>" + 
        "Something version" + 
        "<select id='JS_ImportVersion' name='" + x + "_ImportVersion' style='width:100%'>" + 
         "<option>Something version</option>" + 
        "</select>" + 
       "</td>" + 
       "<td>" + 
        "Something Charachter" + 
        "<select id='JS_ImportChaSet' name='" + x + "_ImportChaSet' style='width:100%'>" + 
         "<option>Something Cha</option>" + 
        "</select>" + 
       "</td>" + 
      "</tr>" + 
      "<tr>" + 
       "<td colspan='2'>" + 
        "Additional Requests </br>" + 
        "<textarea rows='4' id='" + x + "_specialReq' cols='37'> </textarea>" + 
       "<td/>"+ 
      "</tr>"+ 
      "</table>"; 
     rowDetails.style.display = 'none'; 
     Lock(); 
    } 
} 
document.getElementById("instalationTable").style.display = "block"; 

}

我在上表中的行填充形式,收集一些数据以继续。收集我使用下面的函数数据的正常工作与谷歌Chrome,但不是与Internet Explorer ..

function getAllData() { 
var StringtoSent = ""; 
for (i = 0; i < (elementsInTable.length) ; i++) { 
    var InsId = elementsInTable[i]; 
    var _appServer = document.getElementById((i + 1) + "_appServer").checked; 
    var _appServerVersionDropDown = document.getElementById((i + 1) + "_appServerVersion"); 
    var _appServerVersion = _appServerVersionDropDown.options[_appServerVersionDropDown.selectedIndex].value; 
    var _emptyDb = document.getElementById((i + 1) + "_emptyDb").checked; 
    var _instalationSlt = document.getElementById((i + 1) + "_instalationSlt").checked; 
    var _oraVersionDropDown = document.getElementsByName((i + 1) + "_oraVersion")[0]; 
    var _oraVersion = _oraVersionDropDown.options[_oraVersionDropDown.selectedIndex].value; 
    var _ChaSetDropDown = document.getElementsByName((i + 1) + "_ChaSet")[0]; 
    var _ChaSet = _ChaSetDropDown.options[_ChaSetDropDown.selectedIndex].value; 
    var _ImportVersionDropDown = document.getElementsByName((i + 1) + "_ImportVersion")[0]; 
    var _ImportVersion = _ImportVersionDropDown.options[_ImportVersionDropDown.selectedIndex].value; 
    var _ImportChaSetDropDown = document.getElementsByName((i + 1) + "_ImportChaSet")[0]; 
    var _ImportChaSet = _ImportChaSetDropDown.options[_ImportChaSetDropDown.selectedIndex].value; 
    var _specialReq = document.getElementById((i + 1) + "_specialReq").value; 

    StringtoSent = StringtoSent + "," + InsId + "," + _appServer + "," + _appServerVersion + "," + _emptyDb + "," + _instalationSlt + "," + _oraVersion + "," + _ChaSet + "," + _ImportVersion + "," + _ImportChaSet + "," + _specialReq + "|"; 
    //return StringtoSent; 
    document.getElementById("ActivityDescription_instalationDetails").value = StringtoSent; 

} 

}

下图显示了即时得到当它在VS 2012S IIS搞坏了错误表现。 enter image description here

for (i = 0; i < (elementsInTable.length) ; i++) { 

是指示作为错误的地点。它总是突出显示“elementsInTable.length”代码段。

其实这个错误信息没有详细说明。我发现了一些关于相同错误的文章,但在尝试更改元素的内部HTML时发生。但是这些解决方案都没有出现这种情况兼容。请帮助我的问题

在此先感谢

+4

哪条线是238 ...? – 2014-10-30 10:26:34

+0

我认为它在Chrome中无法正常工作。但VS与VS有联系,当出现错误时它会抛出一个异常。查看Chrome控制台。有没有相同的错误? – 2014-10-30 10:28:25

+0

for(i = 0; i <(elementsInTable.length); i ++){这是行抱歉!!!! – Sandaru 2014-10-30 10:46:39

回答

2

终于让我找到在上面一行的错误

 cell.innerHTML = "<table style='background-color:rgb(98, 98, 98);color:black;border- radius: 5px;' margin:2%; >" + 

我错误地添加了一个CSS属性“余量:2%;”进入一个错误的地方。谷歌浏览器的智能足以管理情况并开展活动,但Internet Explorer并非如此。正如我发现的那样,这是在不同情况下提示相同错误的事实。

EG:

http://www.webdeveloper.com/forum/showthread.php?22946-innerHTML-amp-IE-Unknown-Runtime-Error http://www.webdeveloper.com/forum/showthread.php?22946-innerHTML-amp-IE-Unknown-Runtime-Error

所以,如果你有你的Java脚本代码的任何未知错误,它采用“element.InnerHTML”或“文件撰写”它能够更好地检查你的代码是否是妥善关闭。

,我发现,在产生相同的错误

  1. IE shows run time error for innerHTML
  2. InnerHTML issue in IE8 and below

大部分的时间,你可以通过以下W3C标签建议(http://www.w3.org/TR/html401/struct/global.html)避免此类错误的其他情形。

相关问题