Magento中的jQuery

Ism*_*ilp 3 jquery slider magento

我在jQuery中写了一个小滑块脚本,我想在我的Magento商店中运行.我已将此脚本包含在我的view.phtml中,但它似乎不起作用.我究竟做错了什么?我对Magento很新,不知道如何添加自定义脚本.

<script type="text/javascript">// < ![CDATA[
        jQuery(document).ready(function(){
        var active = 0; // starts at zero
        var list = jQuery('ul');

        list.children('li').eq('0').siblings().hide(); // Hide all except first list element

       jQuery('.next').bind('click', function() {
            active = active == list.children('li').length-1 ? 0 : active + 1;
        });

        jQuery('.prev').bind('click', function() {
            active = active == 0 ? list.children('li').length-1 : active - 1;
        });

        var getActive = function() {
            return list.children('li').eq(active);
        };

        jQuery('.prev,.next').bind('click', function() {
            getActive().fadeIn().siblings().hide();
        });

 });// ]]></script>
Run Code Online (Sandbox Code Playgroud)

这是我在view.phtml中的HTML:

<ul>
   <li>img1</li>
   <li>img1</li>
   <li>img1</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

bal*_*dre 9

首先要做的事情是:Magento不使用jQuery.

Magento使用PrototypeJs,要么将jQuery转换为PrototypeJs,要么加载jQuery,使用该noConflict方法使它们无缝运行.

要在页面中加载jQuery,要么使用.xml模板将其加载到所有页面中,要么仅在此特定页面中加载jQuery ,您只需在脚本之前加载它,例如:

<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
// <![CDATA[
   // noConflict so we can use both libraries
   $.noConflict(); 

   // your current code here

//]]>
</script>
Run Code Online (Sandbox Code Playgroud)

如果你想通过你的设计模板加载所有页面,这是一个建议.