You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IE环境下JS遍历数组访问属性,实现单次alert展示所有提示

问题解决:IE下一次性展示所有提示信息

问题背景

在IE浏览器环境下,现有代码执行时会弹出3次提示窗,需求改为仅弹窗一次,按指定格式展示所有错误信息。

修改后的代码

function LoadData(obj) {
    var ArrayData = $('input[type="hidden"][id^="li"]').map(function() {
        return this.getAttribute("value");
    }).get();

    $.ajax({
        data: {
            GUID: JSON.stringify(ArrayData)
        },
        url: "/LoadOrder/LoadData",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(result) {
            if (result.length > 0) {
                // 初始化弹窗内容,包含开头提示语
                var alertContent = "There are problems with your selections.\n\n";
                // 用IE兼容的for循环遍历数组
                for (var i = 0; i < result.length; i++) {
                    var item = result[i];
                    // 拼接每条错误信息,换行分隔
                    alertContent += item.Desc + " - " + item.EDesc + "\n\n";
                }
                // 移除末尾多余换行后弹窗
                alert(alertContent.trim());
            }
        }
    });
}

核心说明

  • 先将所有提示内容拼接成单一字符串,仅在最后调用一次alert,避免多次弹窗
  • 替换IE不支持的ES6语法:用普通for循环替代for...of,用字符串拼接替代模板字符串${}
  • 用\n控制换行,trim()清理末尾多余空行,保证弹窗格式符合预期

内容的提问来源于stack exchange,提问作者test test

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 02:56:52