【问题标题】:json stringify in IE 8 gives run time error Object property or method not supportedIE 8 中的 json stringify 给出运行时错误 Object property or method not supported
【发布时间】:2012-07-25 02:45:25
【问题描述】:

/* 问题描述-我正在使用 json stringify 方法将 javascript 数组转换为 json 表示法中的字符串。但是我在行中收到一条错误消息“不支持对象属性或方法” hidden.value = JSON.stringify(jsonObj); 这应该可以工作,因为 IE8 支持 stringify。请告知

Full code below  */    
function getgridvalue() {

        var exportLicenseId;
        var bolGrossQuantity;
        var bolNetQuantity;
        var totalBolGrossQty =0 ;
        var totalBolNetQty =0;
        var jsonObj = []; //declare array
            var netQtyTextBoxValue = Number(document.getElementById("<%= txtNetQty.ClientID %>").value);
        var atLeastOneChecked = false;

        var gridview = document.getElementById("<%= ExporterGrid.ClientID %>"); //Grab a reference to the Grid

        for (i = 1; i < gridview.rows.length; i++) //Iterate through the rows
        {

            if (gridview.rows[i].cells[0].getElementsByTagName("input")[0] != null && gridview.rows[i].cells[0].getElementsByTagName("input")[0].type == "checkbox")
            {

                if (gridview.rows[i].cells[0].getElementsByTagName("input")[0].checked)
                {

                    atLeastOneChecked = true;
                    exportLicenseId = gridview.rows[i].cells[8].getElementsByTagName("input")[0].value;
                    bolNetQuantity = gridview.rows[i].cells[5].getElementsByTagName("input")[0].value;

                    if (bolNetQuantity == "") {
                        alert('<%= NetQuantityMandatory %>');
                        return false;
                        }
                    if (!isNumber(bolNetQuantity)) {
                        alert('<%= NetQuantityNumber %>');
                        return false;
                    }

                    totalBolNetQty += Number(bolNetQuantity);
                    jsonObj.push({ ExportLicenseId: Number(exportLicenseId),  BolNetQuantity: Number(bolNetQuantity) });

                }

            }
        }
if (gridview.rows.length > 2 && !atLeastOneChecked)
{
    alert('<%= SelectMsg %>');
                        return false;
                    }



if (totalBolNetQty != 0 && netQtyTextBoxValue != totalBolNetQty)
            {
                alert('<%= NetQuantitySum %>');
                return false;
            }

        var hidden = document.getElementById('HTMLHiddenField');
//        if (!this.JSON) {
//            this.JSON = {};
//        }
        var JSON = JSON || {};
        if (hidden != null) {

            hidden.value = JSON.stringify(jsonObj);

        }

    }

【问题讨论】:

    标签: json internet-explorer-8 stringify


    【解决方案1】:

    使用F12 Developer Tools 检查浏览器模式。 JSON 对象存在,但在 IE7 模式下没有方法。使用 json2 库作为后备。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多