我似乎无法通过我的 Magento 网站将 jQuery 与 Prototype 分开。
我已经使用更改的标签等在 JsFiddle 上工作了,但是当我将它添加到我的 magento 网站时,我不断收到未捕获的语法错误。
页面位于 http://www.asg.co.uk/gadgetclinic/how-it-works
我正在使用的代码是:
<script type="text/javascript">
// First hide them all
$j("#how-it-works .step").hide();
function fades($j.step) {
$j div.fadeIn(300, function () {
if (!$j div.is('last-child')) {
fades($div.next());
}
else{
fades($j("#how-it-works .step:first-child"));
}
});
}
fades($("#how-it-works .step:first-child"));
</script>
HTML 代码是:
<div id="how-it-works">
<img src="{{skin url="images/how-it-works.png"}}" alt="How It Works" />
<div class="step"><h3>Get your box</h3><p>We'll send a suitably sized, pre-paid postage box for your device.</p></div>
<div class="step"><h3>Post your device</h3><p>Safely pack your device in your postage box and return it to us.</p></div>
<div class="step"><h3>Repair in process</h3><p>We will update you if need be whilst your device is repaired.</p></div>
<div class="step"><h3>Get your device</h3><p>Your device will be returned using the service you selected.</p></div>
</div>
任何人都可以帮助我系统地将所有必需的 $ 标签放入 $j 中,或者将 jQuery 与 Prototype 分离所需的任何内容吗?
最佳答案
打开您的 jquery.x.x.x.js 文件并将其添加到其最底部:
jQuery.noConflict();
然后对于您的自定义 jQuery 代码,请使用以下内容:
jQuery(function($){ // Use jQuery with $(...) $('#mySelector').hide(); /* your jquery code....*/ });
这就是我用 Magento 实现 jQuery 的方法。我更喜欢使用 $
作为 jQuery 实例,因为它干净且熟悉。上面的代码包装器允许您执行此操作。
关于javascript - Jquery 与原型(prototype) magento 冲突 - 我怎样才能分开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19661610/