如何包含一个文件,并将其内容包装在一个 `pre` 标签中 [英] How to include a file, and wrap its contents in a `pre` tag

查看:32
本文介绍了如何包含一个文件,并将其内容包装在一个 `pre` 标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个示例,演示如何插入文件内容并将内容包裹在pre标签中 --例如,

插入.txt </pre>.用法是插入代码片段.

以下是它如何工作的示例,但此特定示例不起作用,因为 javascript 代码被视为代码片段.

解决方案

您可以尝试通过 javascript 简单地添加

 标签:

document.write('

');document.write(ajaxRq.responseText);document.write('</pre>');

这不是我喜欢的做事方式,但它有效.jQuery 只会让你输入更少的代码.

I'm looking for an example demonstrating how to insert the contents of a file and wrap the contents in a pre tag -- e.g., <pre ...> insert.txt </pre>. The usage will be to insert code snippets.

The following is an example of how it would work, but this particular example does not work because the javascript code is treated as a code snippet.

<pre . . .>

<script type="text/javascript">
  var ajaxRq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
  ajaxRq.open("GET", "license.txt", false);
  ajaxRq.send(null);
  document.write(ajaxRq.responseText);
</script>

</pre>

解决方案

You can try to simply add the <pre> tags through javascript:

document.write('<pre>');
document.write(ajaxRq.responseText);
document.write('</pre>');

This isn’t my preferred way of doing things but it works. jQuery will just make you type up less code.

这篇关于如何包含一个文件,并将其内容包装在一个 `pre` 标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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