0

内部head标签我有:

<link rel="stylesheet" href="google-code-prettify/prettify.css">
<script src="google-code-prettify/prettify.js"></script>

我有身体标签内的某处:

<div id='code-context'>
    <pre class="prettyprint"><code class="language-js"></code></pre>
</div>

在我的主 css 文件中,我有一些pre应该code覆盖美化:

#code-context pre, #code-context code {
    font-family: 'Ubuntu Mono', monospace;
    width: 80ch;
    white-space: pre-wrap;
}

我故意不包括在内<body onload="prettyPrint()">。加载页面时隐藏,因此#code-context没有必要。在用户触发 jQuery 函数后,代码变得可见:

$('#code-context').show();
var fileSource = "code-to-display.js";
$('code').load(fileSource);
$('.prettyprinted').removeClass('prettyprinted');
prettyPrint();
console.log('succeded!');

我在控制台中收到消息(这意味着一切正常),但实际上我得到的是所有代码的边框,并且代码本身没有颜色编码。

帮助?

4

1 回答 1

0

找到了!

我用 jQueryget()代替了load()它,它起作用了,虽然我不完全明白为什么。

于 2016-04-24T03:08:58.283 回答