<script language="javascript">
var theHTML = "";
theHTML += '<script language="javascript">';
theHTML += '<\/script>'; // ('</' + 'script>')
alert (theHTML);
</script>
var theHTML = "";
theHTML += '<script language="javascript">';
theHTML += '<\/script>'; // ('</' + 'script>')
alert (theHTML);
</script>
var theHTML = "";
theHTML += '<' + 'script language="javascript">';
theHTML += '<' + '/script>'; // ('</' + 'script>')
alert (theHTML);
</script>
var theHTML = "";
theHTML += '<script language="javascript">';
theHTML += '<\/script>'; // ('</' + 'script>')
alert (theHTML);
</script>
theHTML += '</script>';
------->
theHTML += '<\/script>';
呵呵,这个俺知道……
-----------------我又在 Opera 7、Netscape 7 浏览器试了一下,同样的结果
-------
也许是我错了,HTML标记的优先级应该是先于 JavaScript语法的
估计浏览器碰到 <script ..>之后,急于寻找闭环的 tag,我那个字符串中的 '</...' 就被匹配上了……
看来也不需要对 / 进行转义了,它不是 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>