将外部javascript文件添加到magento标头 [英] Adding external javascript files to magento header

查看:85
本文介绍了将外部javascript文件添加到magento标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向magento cms添加一些外部javascript文件,但是尽管它们在头部显示得还不错,但是它们似乎不起作用.

I am trying to add some external javascript files to the magento cms but somehow they don't seem to work, though they display alright in the head section.

我正在将以下代码行添加到 head.phtml

I am adding following lines of code to the head.phtml

<!--pankaj js edition-->

<script src="<?php echo $this->getJsUrl(); ?>jQuery_1205141001.js" type="text/javascript"></script>
<script src="<?php echo $this->getJsUrl(); ?>Common_1205141001.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>

呈现页面时,它们显示在头部,但似乎没有完成应做的工作.

They are showing in the head section when the page is rendered, but doesn't seem to do the work they are supposed to be the doing.

是,我做错了.因为文件在简单的html页面中可以很好地工作.我是否需要将文件添加到其他地方.很抱歉打扰,但我是magento的新手.

Am, I doing something wrong. Because the files work well in simple html page. Do i need to add the files somewhere else. Sorry to bother but i am a newbie for magento.

推荐答案

这可能有2个问题

1)您正在尝试在第一行中包含的jQuery_1205141001.js中执行jquery,稍后您将在其中包含jquery库
2)您的jquery与原型冲突.为此,您需要在执行任何jquery代码之前和包括jquery库之后将其添加到phtml中

1) You are attempting to execute jquery in jQuery_1205141001.js which is included in the first line, where as you are including the jquery library later
2) Your jquery is conflicting with prototype. For this you need to add this in the phtml before you execute any jquery code and after including jquery library

<script type="text/javascript">
var $j = jQuery.noConflict();
</script>

,然后使用$ j.function代替$ .function进行jquery 例如

and then use $j.function instead of $.function for jquery e.g.

$j(document.documentElement).keyup(function (event) {

  if (event.keyCode == 37) {

    $j('#prev1').click();
  } else if (event.keyCode == 39) {
    $j('#next1').click();
  }
});

代替

$(document.documentElement).keyup(function (event) {

  if (event.keyCode == 37) {

    $('#prev1').click();
  } else if (event.keyCode == 39) {
    $('#next1').click();
  }
});

这篇关于将外部javascript文件添加到magento标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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