jQuery 与prototypeJS;大小儿童
我目前在 magento 网上商店工作,它加载 PrototypeJS 作为框架。
然而,我有时需要 jQuery 来做一些自定义的事情。
jQuery 在原型之后加载并以 noConflict 模式运行。
现在,这是我的演示 HTML:
<div id="someID">
<div>child</div>
<div>child</div>
<div>child</div>
</div>
加载了一个外部 JS 文件并包含以下内容;
var $j = jQuery.noConflict();
$j(document).ready(function() {
alert($j('#someID').children().length);
});
我的警报显示“1”(在任何选择器上),而预期为 3。
诡异的?!
I currently work on a magento webshop, which loads PrototypeJS as framework.
However i need jQuery at some point to do some custom stuff.
jQuery is loaded after prototype and runs in noConflict mode.
Now, here's my demo HTML:
<div id="someID">
<div>child</div>
<div>child</div>
<div>child</div>
</div>
An external JS file is loaded and contains the following;
var $j = jQuery.noConflict();
$j(document).ready(function() {
alert($j('#someID').children().length);
});
My alert shows '1' (on any selector) where 3 is expected.
Weird?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,找到了解决方案:
Script.aculo.us 已过时,我更新到最新版本,一切都很好:)
请参阅:
http://www.magentocommerce.com/wiki/how-to/how_to_use_jquery_1 .2.6_lastest_with_prototype
OK, found the solution:
Script.aculo.us was outdated, i updated to the latest version and everything is just fine :)
See:
http://www.magentocommerce.com/wiki/how-to/how_to_use_jquery_1.2.6_lastest_with_prototype
在测试文件中仅使用该代码,我得到了正确的值。是否有可能使用其他代码从 DOM 中删除或重新排列其他元素?
Using only that code alone in a test file, I get the proper value. Is it possible that the other elements are being removed from or rearranged in the DOM using some other code?