Jquery与原型magento冲突 - 我如何分开? [英] Jquery conflicting with prototype magento - How can i separate?

查看:70
本文介绍了Jquery与原型magento冲突 - 我如何分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法通过我的Magento网站将jQuery与Prototype分开。

I can't seem to be able to separate jQuery from Prototype with my Magento website.

我已经使用更改的标签等工作JsFiddle但是当我将它添加到我的magento网站,我一直收到未被捕获的语法错误。

I've got it working on JsFiddle using changed tags etc but when i add it to my magento site, i keep getting uncaught syntax errors.

页面位于 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或需要分离的任何内容来自Prototype的jQuery?

Can anyone help me systematically help put all the required $ tags into $j or whatever is needed to separate jQuery from Prototype?

推荐答案


  1. 打开 jquery.xxxjs 文件并将其添加到最底层: jQuery.noConflict();

  1. Open your jquery.x.x.x.js file and add this to the very bottom of it: jQuery.noConflict();

然后,对于您的自定义jQuery代码,请使用以下命令:

Then for your custom jQuery code, use the following:

jQuery(function($){
// Use jQuery with $(...)

    $('#mySelector').hide();

    /* your jquery code....*/

});


这就是我用Magento实现jQuery的方法。我更喜欢使用 $ 作为jQuery实例,因为它很干净且熟悉。上面的代码包装器允许你这样做。

That is how I implement jQuery with Magento. I prefer to use the $ for the jQuery instance as it's clean and familiar. The above code wrapper allows you to do this.

这篇关于Jquery与原型magento冲突 - 我如何分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆