我使用smarty给js传值,也正常解析了html中原来的代码(效果正常):
复制代码
           <TD><A href="#"><IMG src="imgbeb/nav1.gif" width="117" height="45" border=0
            onmouseover="this.src='imgbeb/nav01.gif';" onmouseout="this.src='imgbeb/nav1.gif'"></A></TD>
          <TD><A href="#"><IMG src="imgbeb/nav2.gif" width="105" height="45" border=0
            onmouseover="this.src='imgbeb/nav02.gif';" onmouseout="this.src='imgbeb/nav2.gif'"></A></TD>
          <TD><A href="#"><IMG src="imgbeb/nav3.gif" width="106" height="45" border=0
            onmouseover="this.src='imgbeb/nav03.gif';" onmouseout="this.src='imgbeb/nav3.gif'"></A></TD>smarty替换后的代码(原路径前加{$sty->template_dir}/):
复制代码
<TD><A href="#"><IMG src="{$sty->template_dir}/imgbeb/nav1.gif" width="117" height="45" border=0
            onmouseover="this.src='{$sty->template_dir}/imgbeb/nav01.gif';" onmouseout="this.src='{$sty->template_dir}/imgbeb/nav1.gif'"></A></TD>
          <TD><A href="#"><IMG src="{$sty->template_dir}/imgbeb/nav2.gif" width="105" height="45" border=0
            onmouseover="this.src='{$sty->template_dir}/imgbeb/nav02.gif';" onmouseout="this.src='{$sty->template_dir}/imgbeb/nav2.gif'"></A></TD>
          <TD><A href="#"><IMG src="{$sty->template_dir}/imgbeb/nav3.gif" width="106" height="45" border=0
            onmouseover="this.src='{$sty->template_dir}/imgbeb/nav03.gif';" onmouseout="this.src='{$sty->template_dir}/imgbeb/nav3.gif'"></A></TD>
前台预览——查看页面的源代码(mvc模式下View与index在同一路径下):
复制代码
<TD><A href="#"><IMG src="View/template/imgbeb/nav1.gif" width="117" height="45" border=0
            onmouseover="this.src='View/template/imgbeb/nav01.gif';" onmouseout="this.src='View/template/imgbeb/nav1.gif'"></A></TD>
          <TD><A href="#"><IMG src="View/template/imgbeb/nav2.gif" width="105" height="45" border=0
            onmouseover="this.src='View/template/imgbeb/nav02.gif';" onmouseout="this.src='View/template/imgbeb/nav2.gif'"></A></TD>
          <TD><A href="#"><IMG src="View/template/imgbeb/nav3.gif" width="106" height="45" border=0
            onmouseover="this.src='View/template/imgbeb/nav03.gif';" onmouseout="this.src='View/template/imgbeb/nav3.gif'"></A></TD>页面正常,但就是onmouseover 和onmouseout的效果都不能正确显示,
火狐浏览器下,鼠标放上去的时候,tr下面的td里面的一行图片就不停的抖动
遨游浏览器下,鼠标放上去的时候,图片不显示,鼠标移走的时候又正常

解决方案 »

  1.   

    浏览器并不关心你用没用什么模板引擎。
    仔细比较了一下,除了路径变化外,并没有发现前后的HTML代码有什么差别。但元素之外的布局变没变我就不清楚了
    就你的问题
    火狐浏览器下,鼠标放上去的时候,tr下面的td里面的一行图片就不停的抖动
        抖动的话,我估计应该是切换的图片大小的变化,导致鼠标一会在元素里,切换后又到元素外,所以两个事件相互作用,图片被不停地切换
    遨游浏览器下,鼠标放上去的时候,图片不显示,鼠标移走的时候又正常
        图片不显示,是没有成功加载出错了,还是怎的?另外建议你给 img标签内末尾加个 /  <img /> 这样才符合w3c标准
      

  2.   

    php输出js代码(包括通过smarty)需要注意的是,很容易错误的输出某些字符导致js不能正确执行。比如分号、引号、换行。
      

  3.   

    设置一下smarty的开始和结束标记,建议使用<!-- 和 --> 这样就不会与js或者css之类的发生冲突了.
      

  4.   

    #1楼正解,<img src="/path/……" />