1

所以我目前正在开发一个 Magento 网站。我使用此处找到的代码设置了一个旋转器:

http://www.magentocommerce.com/wiki/4__-_themes_and_template_customization/cms_and_home_page/javascript_banner_rotator_for_home_page

如果我将代码放入主页,它会按预期工作。但是,如果我将代码放在静态块中,CDATA 会强制自己进入代码,从而破坏它。我无法删除 CDATA,因为它不断自我替换。下面的代码:

<script type="text/javascript">// <![CDATA[
var imgs1 = new Array("{{media url="wysiwyg/rotator-1-1.jpg"}}","{{media url="wysiwyg/rotator-1-2.jpg"}}","{{media url="wysiwyg/rotator-1-3.jpg"}}");
var lnks1 = new Array("http://www.example.com/","http://www.example.com/","http://www.example.com/");
var alt1 = new Array("That Looks Nice","That Looks Nice","That Looks Nice");
var currentAd1 = 0;
var imgCt1 = 3;
function cycle1() {
  if (currentAd1 == imgCt1) {
    currentAd1 = 0;
  }
var banner1 = document.getElementById('adBanner1');
var link1 = document.getElementById('adLink1');
  banner1.src=imgs1[currentAd1]
  banner1.alt=alt1[currentAd1]
  document.getElementById('adLink1').href=lnks1[currentAd1]
  currentAd1++;
}
  window.setInterval("cycle1()",4000);
// ]]></script>
<p><a id="adLink1" target="_top"> <img id="adBanner1" src="{{media url="wysiwyg/rotator-1-1.jpg"}}" alt="" width="235" height="250" border="0" /></a></p>

任何帮助,将不胜感激。

4

1 回答 1

0

您正在评论 javascript 结束</script>标记,请尝试</script>在 CDATA 行结束之后放置。不确定这一点,但值得一试。

于 2012-10-22T11:49:58.523 回答