Magento:自定义文件中的jQuery不起作用

时间:2014-06-03 04:51:59

标签: javascript jquery xml magento

所以我想尝试将一些简单的jQuery添加到magento-theme中。 我把我的jQuery放在一个外部文件中,该文件位于" js"主题的(skin / frontend / default / myTheme / js)文件夹。 以下是我网站的链接:http://shop.veivecouture.com/ 我使用以下方法将其包含在page.xml文件中:

<action method="addItem"><type>skin_js</type><name>js/functions.js</name></action>

我也尝试过:

<action method="addJs"><script>../skin/frontend/default/trego/js/functions.js</script></action>

我把它们都放在&#34; Head&#34;阻止这样:

<block type="page/html_head" name="head" as="head">
   <action method="addJs"><script>prototype/prototype.js</script></action>
   <action method="addJs"><script>lib/ccard.js</script></action>
   <action method="addJs"><script>prototype/validation.js</script></action>
   <action method="addJs"><script>scriptaculous/builder.js</script></action>
   <action method="addJs"><script>scriptaculous/effects.js</script></action>
   <action method="addJs"><script>scriptaculous/dragdrop.js</script></action>
   <action method="addJs"><script>scriptaculous/controls.js</script></action>
   <action method="addJs"><script>scriptaculous/slider.js</script></action>  
   <action method="addJs"><script>varien/js.js</script></action>
   <action method="addJs"><script>varien/form.js</script></action>
   <action method="addJs"><script>varien/menu.js</script></action>
   <action method="addJs"><script>mage/translate.js</script></action>
   <action method="addJs"><script>mage/cookies.js</script></action>

   <block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
    <action method="addItem"><type>skin_js</type><name>js/functions.js</name></action> <!-- my line -->

    <action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
    <action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
    <action method="addCss"><stylesheet>css/widgets.css</stylesheet></action>
    <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>
    <action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
    <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>
</block>

我可以通过&#34;查看源&#34;来获取这两个文件,因此链接似乎是正确的,但是没有jQuery生效。 我做错了什么?

这是functions.js文件中的javascript:

$('.block-content').hide(); //edit by Carl Papworth
$('.block-title').click(function(e){
    e.preventDefault();
    $('.block-content').show();
    $('.close-block').click(function(e){
        e.preventDefault();
        $('.block-content').hide();
    });
});

3 个答案:

答案 0 :(得分:0)

将文件放入magento js文件夹并尝试

    <action method="addJs"><script>js/your_custom_folder/functions.js</script></action>

答案 1 :(得分:0)

尝试在js文件的最底部添加jQuery.noConflict();

答案 2 :(得分:0)

将此添加到您的头部:

<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/specification.js');?>" media="screen"></script>