<script language="javascript">
var theHTML = "";
theHTML += '<script language="javascript">';
theHTML += '<\/script>'; // ('</' + 'script>')
alert (theHTML);
</script>

解决方案 »

  1.   

    <script language="javascript">
    var theHTML = "";
    theHTML += '<' + 'script language="javascript">';
    theHTML += '<' + '/script>'; // ('</' + 'script>')
    alert (theHTML);
    </script>
      

  2.   

    我认为这是浏览器的 bug
      

  3.   

    出现 未结束的字符串常量 这样的错误 一般是‘与” 这两个符号混淆不清造成的!<script language="javascript">
    var theHTML = "";
    theHTML += '<script language="javascript">';
    theHTML += '<\/script>'; // ('</' + 'script>')
    alert (theHTML);
    </script>
      

  4.   

    需要用"\"对"/"进行转义
    theHTML += '</script>';
    ------->
    theHTML += '<\/script>';
      

  5.   

    >> 直接用你注释的那个就行了
    呵呵,这个俺知道……
    -----------------我又在 Opera 7、Netscape 7 浏览器试了一下,同样的结果
    -------
    也许是我错了,HTML标记的优先级应该是先于 JavaScript语法的
    估计浏览器碰到 <script ..>之后,急于寻找闭环的 tag,我那个字符串中的 '</...' 就被匹配上了……
      

  6.   

    没错,'</script>' 的确是匹配为 html 的 closed tag 了这是 http://validator.w3.org 检测的结果
    看来也不需要对 / 进行转义了,它不是 JavaScript 的特殊字符
    -----------
    Source Listing
    Below is the source input I used for this validation:   1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
       2: 
       3: <html>
       4: 
       5: <head>
       6: <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
       7: <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
       8: <meta name="ProgId" content="FrontPage.Editor.Document">
       9: <title>New Page 1</title>
      10: </head>
      11: 
      12: <body>
      13: 
      14: <script type="text/javascript">
      15:  var theHTML = "";
      16:  theHTML += '<script language="javascript">';
      17:  theHTML += '</script>'; // ('<' + '/script>')
      18:  alert (theHTML);
      19: </script>
      20: </body>
      21: 
      22: </html>
        
    Parse Tree
    I am excluding the attributes, as you requested. <HTML>
      <HEAD>
        <META>
        </META>
        <META>
        </META>
        <META>
        </META>
        <TITLE>
           New Page 1
        </TITLE>
      </HEAD>
      <BODY>
        <SCRIPT>
           var theHTML = ""; theHTML += '<script
          language="javascript">'; theHTML += '
        </SCRIPT>
         '; // ('<' + '/script>') alert (theHTML); 
      </BODY>
    </HTML>