使用< pre>和< code>用于显示javascript脚本的标签 [英] Using <pre> and <code> tags to display a javascript script

查看:327
本文介绍了使用< pre>和< code>用于显示javascript脚本的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试验< pre>和<代码> html 5中的标签,因为我想在我的网站上包含一些代码片段。我正在使用下面的页面作为测试页面,但它没有显示任何内容。有什么理由?

I'm experimenting with the < pre> and < code> tags in html 5 as I would like to include some code snippets on my website. I'm using the page below as a test page but it is not displaying anything. Any reason why?

    <body>
    <div style="color:#000000">
      <pre>
        <code>
          <script type="text/javascript">
            $('#inputField').hide();
          </script>
        </code>
      </pre>
    </div>
    </body>

我的理解是使用这些新标签会否定它们包含的任何代码但是这不会似乎是这种情况。

It was my understanding that using these new tags would negate any code that they contain within however this does not appear to be the case.

干杯,

J

推荐答案

这些标签仅用于装饰目的。内部代码仍将执行。如果您希望显示它,您必须至少将< script> 标记转换为html:

These tags are only for "decorational" purposes. Code within will still be executed. If you want it displayed you have to convert at least the <script> tag to html:

&lt;script type="text/javascript"&gt;

然后将显示中间的JavaScript代码。

Then the JavaScript code inbetween will be shown.

你不需要两者,我会使用< pre> (默认情况下是一个块元素),< code> ; 用于内联使用。

You don't need both though, I would use <pre> (which is per default a block element), <code> is intended for inline use.

这篇关于使用&lt; pre&gt;和&lt; code&gt;用于显示javascript脚本的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆