Magento中的jQuery

Magento中的jQuery,jquery,magento,slider,Jquery,Magento,Slider,我在jQuery中编写了一个小滑块脚本,我想在我的Magento存储中运行它。我已经在我的view.phtml中包含了这个脚本,但它似乎不起作用。我做错了什么?我是Magento的新手,不知道如何添加自定义脚本 <script type="text/javascript">// < ![CDATA[ jQuery(document).ready(function(){ var active = 0; // starts at zero

我在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>
/<![CDATA[
jQuery(文档).ready(函数(){
var active=0;//从零开始
var list=jQuery('ul');
list.children('li').eq('0').sibbines().hide();//隐藏除第一个列表元素以外的所有元素
jQuery('.next').bind('click',function(){
active=active==list.children('li')。长度-1?0:active+1;
});
jQuery('.prev').bind('click',function(){
active=active==0?list.children('li')。长度-1:active-1;
});
var getActive=function(){
返回列表.children('li').eq(活动);
};
jQuery('.prev,.next').bind('click',function(){
getActive().fadeIn().Sides().hide();
});
});// ]]>
这是我在view.phtml中的HTML:

<ul>
   <li>img1</li>
   <li>img1</li>
   <li>img1</li>
</ul>
  • img1
  • img1
  • img1

第一件事:Magento不使用jQuery

Magento使用,或者将jQuery转换为PrototypeJs,或者必须加载jQuery,使用该方法使它们无缝运行

要在页面中加载jQuery,您可以使用
.xml
模板将其加载到所有页面中,或者如果它仅在这个特定页面中,您可以在脚本之前加载它,例如:

<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>

// 

如果要通过设计模板加载所有页面,.

Thanx!我为Magento添加了jQuery扩展,这就是我使用jQuery的原因。我从未使用过原型。有什么简单的方法可以将代码转换成prototype.js吗?没有,而且我对prototype也不太熟悉,只了解一些基本的东西。。。使用Magento论坛询问该扩展或搜索该扩展的帮助,如果您已安装,当然,刷新缓存,但仍然无法工作,请执行此操作,或完全删除它,然后应用我提供的示例代码/阅读提供的链接,手动加载所有页面的jQuery。