首页 > 运营 > 帮助中心 > 正文

如何在ecshop中使用JS代码

2019-10-16 21:45:41
字体:
来源:转载
供稿:网友

 有一个菜单效果是由HTML代码和JS代码组成的,准备放到首页和内容页用,以前在别的程序都使用过,像动易、领智、风讯、E商务的Medi等等都很好用,就是放到一个普通的HTML静态页面也一样正常使用,可就是放到ECShop中无法正常使用,请问管理员是什么原因,以下是菜单效果的代码和在ECShop中测试使用的几种方法

 
一、菜单效果的代码(CSS代码没贴)
<script language="javascript">
function switchTag(tag,content)
{
//        alert(tag);
//        alert(content);
        for(i=1; i <6; i++)
        {
                if ("tag"+i==tag)
                {
                        document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i;
                        document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="selectspan"+i;
                }else{
                        document.getElementById("tag"+i).getElementsByTagName("a")[0].className="";
                        document.getElementById("tag"+i).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="";
                }
                if ("content"+i==content)
                {
                        document.getElementById(content).className="";
                }else{
                        document.getElementById("content"+i).className="hidecontent";
                }
                document.getElementById("content").className=content;
        }
}
</script>
 
<div id="container">
  <div id="title">
    <ul>
      <li id="tag1"><a href="#" onclick="switchTag('tag1','content1');this.blur();" class="selectli1"><span class="selectspan1">首页</span></a></li>
      <li id="tag2"><a href="#" onclick="switchTag('tag2','content2');this.blur();"><span>下载中心</span></a></li>
      <li id="tag3"><a href="#" onclick="switchTag('tag3','content3');this.blur();"><span>产品介绍</span></a></li>
      <li id="tag4"><a href="#" onclick="switchTag('tag4','content4');this.blur();"><span>会员注册与登录</span></a></li>
      <li id="tag5"><a href="#" onclick="switchTag('tag5','content5');this.blur();"><span>联系我们</span></a></li>
    </ul>
  </div>
<div id="content" class="content1">
  <div id="content1"><p>仿淘宝网站的导航效果。此方法有几个优点:</p>1、根据字数自适应项目长度</div>        
  <div id="content2" class="hidecontent">2、不同的项目使用不同的颜色来区分</div>
  <div id="content3" class="hidecontent">3、这回需要使用到js了,呵呵</div>
  <div id="content4" class="hidecontent">4、背景图片只需要两个图片文件就足够,减少服务器负担</div>
  <div id="content5" class="hidecontent">5、这是使用到的两个图片:
         <table width="58%" border="1" cellspacing="2" cellpadding="0">
           <tr>
             <td width="70%" align="center"><img src="upload/2006981132247255.gif" width="250" height="290" /></td>
             <td width="30%" align="center"><img src="upload/20069811321034000.gif" width="15" height="290" /></td>
           </tr>
         </table>
  </div>
</div>  
 
</div>
 
二、在ECShop中测试使用的几种方法
1、把整个的代码(包括JS和HTML代码)放到了index.dwt模板相应的位置,结果预览首页时只出现以下代码:
Fatal error: Smarty error: [in index.html line 45]: syntax error: unrecognized tag: // alert(tag); // alert(content); for(i=1; i <7; i++) { if ("tag"+i==tag) { document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i; document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="selectspan"+i; (Smarty_Compiler.class.php, line 439) in F:/ecshop/includes/smarty/Smarty.class.php on line 1095
2、把JS代码放到了<head></head>之间,HTML代码还放在了模板原来的位置,结果跟第一种方法相同
3、把js代码存成了一个JS文件这样<scritpt type="text/javascript" src="themes/default/***.js"><script>在<head></head>之间调用,HTML代码还放在了模板原来的位置,结果预览首页时页面的左下角虽然有“网页上有错误”的提示但还是可以正常显示,可就是js所控制的动作不起作用了
 
 
在群里有说JS和SMARTY是有冲突的,不能把JS代码直接写到模板文件里,要存成JS文件调用,不知道是否正确,而且我也把js代码存成了一个JS文件调用了,
 
把script套在{literal}{/literal}之间试试看,例如:

  1. {literal}
  2. <script type="text/javascript">
  3. ....
  4. </script>
  5. {/literal}
 
 
 
 
 
IFrame框架代码:
 
<iframe src="http://www.cuoxin.com&style=0&frame=1" width=88 height=31 frameborder=0></iframe>
 
  1. <div style="display:none;">
  2. <script src="http://union.volit.com/show.php?webid=120256&style=0"></script>
  3. <iframe src="http://union.volit.com/show.php?webid=120256&style=0&frame=1" width=88 height=31 frameborder=0></iframe>
  4. </div>
 
 
 
 
 
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表