javascript - Jquery 与原型(prototype) magento 冲突 - 我怎样才能分开?

标签 javascript jquery magento prototype conflict

我似乎无法通过我的 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 分离所需的任何内容吗?

最佳答案

  1. 打开您的 jquery.x.x.x.js 文件并将其添加到其最底部:jQuery.noConflict();

  2. 然后对于您的自定义 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/

相关文章:

javascript - 如何使用 jsonp 调用返回的数据在 Durandal 中呈现 View ?

javascript - 使用 % 宽度时的 JScrollPane 问题

javascript - 将innerHTML 与Greasemonkey 结合使用

Magento:以编程方式加载产品属性 - 如何?

javascript - 如何隐藏错误信息?

javascript - 使用 Javascript 从日期中减去工作日

jquery - $wpdb->insert 在格式化后分割我的日期

mysql - 如果产品库存中剩下一件商品,Magento SQLSTATE 错误

html - Magento eshop 1.7.0.2 的响应式设计方法

javascript - 数据表中的流程图