为什么 Magento 中的原型代码会崩溃?
在过去的一个半小时里,我在我正在构建的 Magento 商店中跟踪了 Javascript 调用,因为我有一个奇怪的效果,即结账时,我无法留下单页结账的第 2 页(送货地址),除非我从“发送到这个地址”切换到“发送到另一个地址”。
我已经将其追溯到 form.js 中的这段 javascript 代码,位于 Regionupdater.setMarkDisplay (第 254 行以下)。
由于我自己是一个 jquery 人,所以我并没有真正参与原型功能的循环,但我'我假设 .up 和 .down 实际上就是 jquery 对 .parent(s) 和 .children() 所做的事情?!
elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') ||
elem.up(1).down('label > span.required') ||
elem.up(0).down('label.required > em') ||
elem.up(1).down('label.required > em');
elem 是表单中的区域选择字段。 我假设它正在尝试查找该字段的标签(存在)。但两个“elem.up(0)”片段显然都会抛出一个“
[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)"]
我不知道是什么触发了这个”。
For the last hour and a half I've trace Javascript calls in a Magento shop I'm building, because I have the strange effect that, when checking out, I can not leave page 2 (shipping address) of the onepage checkout, unless I switch from "send to this address" to "send to another address".
I've traced it down to this piece of javascript code in form.js, residing in Regionupdater.setMarkDisplay (line 254 ff.)
Since I'm a jquery man myself I'm not really in the loop with prototype functionality but I'm assuming .up and .down are practically what jquery does with .parent(s) and .children()?!
elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') ||
elem.up(1).down('label > span.required') ||
elem.up(0).down('label.required > em') ||
elem.up(1).down('label.required > em');
elem is the region select field in the form.
I'm assuming it's trying to find the label for this field (which exists). But both the "elem.up(0)" fragments apparently throw an
[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)"]
I've no idea what triggers this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您基本上对
up
和 < a href="http://api.prototypejs.org/dom/element/down/" rel="nofollow noreferrer">down
即可。该行代码正在选择第一个匹配元素:...在每种情况下,它都会在找到的第一个元素处停止。
该错误看起来像是从选择器引擎抛出的,或者是传递给它不理解的选择器的东西。这些选择器都不是特别前沿,所以这有点奇怪。您使用的是 Prototype 1.7 RC2 吗?因为当前发布的Prototype仍然只使用自己内置的选择器引擎(而1.7添加了可插入的选择器引擎)。
啊!就是这样 - 查看该区域中元素的
id
。它们中是否有空格或“#”或“:”之类的东西?我似乎记得原型选择器引擎中的一个错误,它假设相当无聊的ID...(为什么ID是相关的?在幕后,选择器引擎可能在处理后代或子选择器时使用它们——例如,在处理< code>down 调用...)更新 这个(已修复)错误可能与此相关,如果您使用的是旧版本的 Prototype,您可能仍然会遇到它。绝对值得一看 ID。
You're basically right about what
up
anddown
do. That line of code is picking the first matching element:...where in each case it stops with the first one it finds.
The error looks like it's being thrown from a selector engine or something being passed a selector it doesn't understand. None of those selectors is particularly cutting-edge, so that's a bit strange. Are you using Prototype 1.7 RC2? Because the current released Prototype still only uses its own built-in selector engine (whereas 1.7 adds pluggable ones).
Ah! That's it -- look at the
id
s of the elements in that area. Do any of them have spaces or '#' or ':' in them, that sort of thing? I seem to recall a bug in the Prototype selector engine where it assumes fairly boring IDs... (Why are IDs relevant? Under the covers, the selector engine may use them when processing descendant or child selectors -- for instance, when processingdown
calls...)Update This (fixed) bug may relate to this, if you're using an older version of Prototype you may still be running into it. Definitely worth looking at the IDs.
我在 IE8 上有同样的错误,但就我而言,这不是因为未转义的冒号。我遇到错误是因为我使用的是修改 DOM 的自定义主题,因此 elem.up(0) 指向其他元素。
您应该查看 Skin/frontend/your_template/js/opcheckout.js 第 420 行和 428 行
函数 setSameAsBilling 和syncWithBilling 或更改您的模板文件 - Shipping.phtml。
此外,在默认皮肤上也不会出现此错误。
I have the same error, on IE8, but in my case it's not because of unescaped colon. I have the error because I'm using a custom theme that modified the DOM so elem.up(0) is pointing to other element.
You should look at skin/frontend/your_template/js/opcheckout.js at lines 420 and 428
functions setSameAsBilling and syncWithBilling or change your template file - shipping.phtml.
Also on default skin this error does not apear.