为什么 Magento js/varien/form.js IE 中的错误 - js fiddle

Why Magento js/varien/form.js error in IE - js fiddle

本文关键字:js 错误 fiddle form Magento varien 为什么 IE      更新时间:2023-09-26

这似乎是很多人遇到的问题!链接到谷歌搜索结果

有很多答案,

我已经研究了一些更合理的答案,并修复了页面上的任何JavaScript错误。在 Chrome 中我没有发现任何错误,但在 IE8 中,我在第 205 行错误上收到无效参数,并且状态下拉列表丢失。我不是JavaScript专家,不知道从哪里开始解决此问题。特别是当涉及到浏览器细节时。

问题的屏幕截图

如果您查看JS中的第205行,则缺少字段,因为它包括:

if (this.regionSelectEl.options.add) {
        this.regionSelectEl.options.add(option);
} else {
        this.regionSelectEl.appendChild(option);
}

这恰好是页面中缺少的区域(状态)选择元素。指向 JS 的链接:http://jsfiddle.net/bms85/LKdsq/1/

可能是什么原因造成的?

编辑:

发现原因是与精简的最新版本的现代化器冲突,我正在为 html5 polyfill 使用现代化器。仍在尝试调试冲突。

我在Magento/Modernizr网站上也遇到了这个问题,Brendan Falkowlski的回答为我指出了一个解决方案。自从他回答以来,Modernizr发布了2.6.x,它将html5siv更新为3.6,其中包括对特定问题的修复。因此,如果您遇到此问题并使用 2.6 之前的现代化,更新到最新版本(使用其捆绑的 html5shiv)应该可以解决问题。

要跨浏览器兼容,您应该这样做

this.regionSelectEl.options[this.regionSelectEl.options.length] = new Option(option.text, option.value);

Magento中的表单.js与IE8中的Modernizr(当包含HTML5siv时)冲突(可能也更低 - 没有测试)。具有表单验证的页面将显示错误消息。

修复:

与其在 Modernizr 中加载 HTML5siv,不如从以下位置下载 html5shiv.js https://github.com/aFarkas/html5shiv

使用此布局 XML 添加仅向 IE8 及更低版本提供 shiv 的条件注释:

<action method="addItem"><type>skin_js</type><name>js/html5shiv.js</name><params/><if>lte IE 8</if></action>

然后,您可以构建自定义 Modernizr 包并包含它。由于所有浏览器都获得 Modernizr 脚本,因此这有一个很好的副作用,即减轻现代浏览器的脚本。

注意:这给IE8用户带来了额外的负担,迫使他们下载额外的脚本,但这比让他们看到错误要好。

事实证明,

IE不喜欢这些选项。

            if (this.regionSelectEl.options.add) {
                this.regionSelectEl.options.add(option);
            } else {
                this.regionSelectEl.appendChild(option);
            }

我只是用了 appendClild 代替。

            if (this.regionSelectEl.options.length > 0 && option.value.length > 0 && option.text.length > 0 && this.regionSelectEl.options.add) {
                //~ this.regionSelectEl.options.add(option);
                this.regionSelectEl.appendChild(option);
            } else {
                this.regionSelectEl.appendChild(option);
            }