原因:这一句的js语法不对,js看到回车就当是语句结束,
------------
   var marqueecontents= ' <font face="Arial" color=#993366 > <strong > <big > 这里有全国32个省市788个频道的电视节目时间表...15,008部影视剧,128,638部网络电视和视频...... 
找到你喜爱的节目,收看精彩视频与电视节目...发表评论、上传剧照,与其他用户一起分享...最重要的是,这一切全都免费! </big > </strong > </font > '; 
-----------
它会当作两句:
第一句
------
   var marqueecontents= ' <font face="Arial" color=#993366 > <strong > <big > 这里有全国32个省市788个频道的电视节目时间表...15,008部影视剧,128,638部网络电视和视频...... 
----------
第二句
---------
找到你喜爱的节目,收看精彩视频与电视节目...发表评论、上传剧照,与其他用户一起分享...最重要的是,这一切全都免费! </big > </strong > </font > '; 
-----------解决方法:
后台字符串输出到前台,要进行转码
输出到html里的,为html特殊字符做转码,
输出到js里的,为js特殊字符做转码。附:
jsp的话可以用以下class来做转码:
-------
/*
 * Created by Seamus
 * Updated on 2004-10-21 by JK
 *
 */
package com.jk.util;public class  CommStr
{
  /**
  *replace the old string to new string in the given destination string.
  */
  public static java.lang.String strReplace(java.lang.String destStr, java.lang.String oldStr, java.lang.String newStr)
  {
    if(destStr==null)
      return "";
    String tmpStr = destStr;
    int foundPos = tmpStr.indexOf(oldStr);
    while (foundPos>=0)
    {
      tmpStr = tmpStr.substring(0,foundPos) + newStr + tmpStr.substring(foundPos + oldStr.length(),tmpStr.length());
      foundPos = tmpStr.indexOf(oldStr,foundPos+newStr.length());
    }
    return tmpStr;
  }  /**
  *Encode for HTML.
  */
  public static String htmlEncoder(String str)
  {
    if(str==null || str.equals(""))
      return "";
    String res_str;
    res_str=strReplace(str,"&","&amp;");
    res_str=strReplace(str," ","&nbsp;");
    res_str=strReplace(str,"<","&lt;");
    res_str=strReplace(str,">","&rt;");
    res_str=strReplace(str,"\"","&quot;");
    res_str=strReplace(str,"'","&#039;");
    return res_str;
  }  /**
  *Encode for HTML-Text.
  */
  public static String htmlTextEncoder(String str)
  {
    if(str==null || str.equals(""))
      return "";
    String res_str;
    res_str=strReplace(str,"&","&amp;");
    res_str=strReplace(str,"<","&lt;");
    res_str=strReplace(str,">","&rt;");
    res_str=strReplace(str,"\"","&quot;");
    res_str=strReplace(str,"'","&#039;");
    res_str=strReplace(str," ","&nbsp;");
    res_str=strReplace(str,"\r\n","<br>");
    res_str=strReplace(str,"\r","<br>");
    res_str=strReplace(str,"\n","<br>");
    return res_str;
  }  /**
  *Encode for URL.
  */
  public static String urlEncoder(String str) {
    return java.net.URLEncoder.encode(str) ;
  }  /**
  *Encode for XML.
  */
  public static String xmlEncoder(String str)
  {
    if(str==null || str.equals(""))
      return "";
    String res_str;
    res_str=strReplace(str,"&","&amp;");
    res_str=strReplace(res_str,"<","&lt;");
    res_str=strReplace(res_str,">","&gt;");
    res_str=strReplace(res_str,"\"", "&quot;");
    res_str=strReplace(res_str,"\'", "&acute;");
    return res_str;
  }  /**
  *Encode for SQL.
  */
  public static String sqlEncoder(String str)
  {
    if(str==null || str.equals(""))
      return "";
    String res_str;
    res_str=strReplace(str,"'","''");
    return res_str;
  }  /**
  *Encode for Javascript.
  */
 public static String jsEncoder(String str)
 {
if(str==null || str.equals(""))
 return "";
String res_str;
res_str=strReplace(str,"\\","\\u005C");
res_str=strReplace(str,"'","\\u0027");
res_str=strReplace(res_str,"\"","\\u0022");
res_str=strReplace(res_str,"\r\n","\\u000A");
res_str=strReplace(res_str,"\n","\\u000A");
res_str=strReplace(res_str,"\r","\\u000A");
res_str=strReplace(res_str,"/","\\u002F");
return res_str;
 }
}

解决方案 »

  1.   

    不知道是不是你想要的结果, 代码如下:<html > 
       <head > 
         <title >文字移动效果 </title > 
       </head > 
       <body > 
       <p > 
       <center > 
       <font color="ffaafa" > <h2 >文字移动效果----上下滚动的文本 </h2 > </font > 
       <hr width=300 > 
       <p > 
       <script lanuage="JavaScript" > 
       var MarqueeWidth=480;      //滚动区域限制不起作用 
       var MarqueeHeight=40; 
       var speed=3; 
       var marqueecontents= ' <font face="Arial" color=#993366 > <strong > <big > 这里有全国32个省市788个频道的电视节目时间表...15,008部影视剧,128,638部网络电视和视频......'+ 
    '找到你喜爱的节目,收看精彩视频与电视节目...发表评论、上传剧照,与其他用户一起分享...最重要的是,这一切全都免费! </big > </strong > </font > '; 
    if(document.all) 

    alert("11111");     //第一个alert能运行 
    document.write ("<marquee direction=\"up\" scrollAmount=\""+speed+"\" width=\""+MarqueeWidth+"\" height=\""+MarqueeHeight+"\" >"+marqueecontents+"</marquee > \r\n");
    alert("22222");     //第二个alert就不能运行了 
    } </script> 
       </body > 
    </html>
      

  2.   

    二楼的结果是正确了,但为什么要把''改写为、\" \"?能不能详细说明一下?
    原语句:
    document.write('<marquee direction="up" scrollAmount='+speed+' stytle="width:'+MarqueeWidth+';height:'+MarqueeHeight+'">'+marqueecontents+'</marquee>');改写后的语句:
    document.write (" <marquee direction=\"up\" scrollAmount=\""+speed+"\" width=\""+MarqueeWidth+"\" height=\""+MarqueeHeight+"\" 
      

  3.   

    其实用'' 和用""都可以, 只是符号的写法不一样而已, 请看以下代码, 你可以试试:这是用""的写法
    document.write ("<marquee direction=\"up\" scrollAmount=\""+speed+"\" width=\""+MarqueeWidth+"\" height=\""+MarqueeHeight+"\" >"+marqueecontents+"</marquee > \r\n");
    而这个是用''的写法
    document.write ('<marquee direction="up" scrollAmount="'+speed+'" width="'+MarqueeWidth+'" height="'+MarqueeHeight+'" >'+marqueecontents+'</marquee > \r\n');