繁体   English   中英

调用Array.length时出现未知错误

[英]Unknown error when calling Array.length

首先,我需要说我对JS没有多少经验。 目前我正在尝试使用MVC框架实现Web应用程序。 我正在开发一个兼容Internet Explorer的应用程序。 在这种情况下,我正在使用以下JS方法来填充一个表格,该表格适用于所有浏览器....

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";

}

我在上表行填充表单,收集一些数据以继续。 收集数据我正在使用以下功能,该功能适用​​于Google 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 Express上破坏时我得到的错误。 在此输入图像描述

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

是指示错误位置的地方。 它总是突出显示“elementsInTable.length”代码段。

实际上这个错误信息没有任何说明。 我发现了一些关于同一错误的文章,但在尝试更改元素的内部HTML时发生了。 但这些解决方案与这种情况不兼容..请帮我解决这个问题

提前致谢

最后我找到了错误

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

在上面的行我错误地添加了一个CSS属性“margin:2%;” 在错误的地方。 谷歌浏览器的智能足以管理情况并继续进行活动,但Internet Explorer却没有。 正如我发现的那样,这是在不同情况下提示相同的错误。

例如:

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未知的运行时错误

因此,如果您在使用“element.InnerHTML”或“document.Write”的Java Script代码中出现任何未知错误,最好检查您的代码是否已正确关闭。

我发现了其他一些产生相同错误的情况

  1. IE显示innerHTML的运行时错误
  2. IE8及以下版本的InnerHTML问题

大多数情况下,您可以通过遵循W3C标记建议来避免此错误( http://www.w3.org/TR/html401/struct/global.html )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM