HTML <pre>标记</script>中<script>标记的位置无效

时间:2015-01-04 19:06:56

标签: javascript html css

我将阅读 JavaScript完整参考第3版 中提供的示例。

作者给出的{strong> O / P here

            <body> 
            <h1>Standard Whitespace Handling</h1> 

            <script>
            // STRINGS AND (X)HTML
            document.write("Welcome to JavaScript strings.\n");
            document.write("This example illustrates nested quotes 'like this.'\n");        
            document.write("Note how newlines (\\n's) and ");
            document.write("escape sequences are used.\n");
            document.write("You might wonder, \"Will this nested quoting work?\"");
            document.write(" It will.\n");
            document.write("Here's an example of some formatted data:\n\n");
            document.write("\tCode\tValue\n");
            document.write("\t\\n\tnewline\n");
            document.write("\t\\\\\tbackslash\n");
            document.write("\t\\\"\tdouble quote\n\n");
            </script>   

            <h1>Preserved Whitespace</h1> 
            <pre>
            <script>           // in Eclipse IDE, at this line invalid location of tag(script)                                             
            // STRINGS AND (X)HTML
            document.write("Welcome to JavaScript strings.\n");
            document.write("This example illustrates nested quotes 'like this.'\n");        
            document.write("Note how newlines (\\n's) and ");
            document.write("escape sequences are used.\n");
            document.write("You might wonder, \"Will this nested quoting work?\"");
            document.write(" It will.\n");
            document.write("Here's an example of some formatted data:\n\n");
            document.write("\tCode\tValue\n");
            document.write("\t\\n\tnewline\n");
            document.write("\t\\\\\tbackslash\n");
            document.write("\t\\\"\tdouble quote\n\n");
            </script>   
            </pre>
            </body>

(X)HTML会自动将 多个空白字符 “折叠”为 一个空白 。因此,例如,在HTML中包含多个连续选项卡只显示一个空格字符。在此示例中, 预标记 用于告诉浏览器 文本已预先格式化,并且不应该折叠其中的空白区域 。同样,我们可以使用 CSS空白属性 来修改标准 空白处理 。使用 pre 可以让示例中的标签在输出中正确显示。

那么,如何摆脱这个警告,我真的需要关注这个吗?我想我错过了一些东西,因为我对作者的直觉没有错?

1 个答案:

答案 0 :(得分:4)

script标记内pre没有错。它只是Eclipse IDE验证问题。如果你在浏览器中使用这个html,一切正常,没有显示警告。

另外,如果您想将脚本标记显示为&#39;文本内容&#39;在预标记内,然后看看这个问题:script in pre