假设localhost指向文件夹www,文件夹结构:
www/
file/test.cpp
index.html
我想动态加载test.cpp并index.html使用highlight.js.
这是中的代码index.html:
<div id="content"></div>
<script>
$.ajax({
url: 'file/test.cpp',
dataType: 'text',
success: function(code) {
$('#content').html($('<pre>').append($('<code>').text(code)));
}
});
<script>
但我得到的是:
<pre><code>
"
...here is the content of test.cpp...
"
</code></pre>
注意内容周围的引号test.cpp?我该如何摆脱它们?他们不应该在那里。因为当我使用时console.log,那些引号不会显示。我想我必须在这里错过一些东西,有人可以帮助我吗?非常感谢。