0
裏面head
標籤我:不成功的嘗試「谷歌代碼美化」與動態DOM
<link rel="stylesheet" href="google-code-prettify/prettify.css">
<script src="google-code-prettify/prettify.js"></script>
某處body標籤裏面,我有:
<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!');
我在控制檯(這意味着一切順利OK)收到消息,但其實我得到的是一個邊框全部代碼和代碼本身沒有顏色編碼。
幫助?
是被加載的CSS文件? – gabe3886
@ gabe3886,我在問題中添加了信息,非常感謝您的幫助。謝謝! – galah92