我正在使用 prettify ,我想知道我是否可以让它与任何 code
block 一起工作,而不需要 prettyprint
类。
否则,我如何动态附加类 prettyprint
,也许使用 jquery。我想要实现的是类似于堆栈溢出,其中在编辑器中键入的代码将在预览和输出中“漂亮地打印”。
我试过了
$("#main").delegate("code", "ready", function() {
// this does not seem to run at all?
// intending to add the prettyprint class here
});
最佳答案
$(document).ready(function(){ $('code').addClass('prettyprint'); });
-
$(document).ready(<func>)
运行<func>
当 DOM 准备就绪时。 -
$('code')
选择所有代码标签。 -
.addClass()
将指定的类添加到它传递的任何元素(在本例中,所有code
标记)。
关于javascript - 我可以让 Prettify 在任何代码块上工作吗?没有类 prettyprint?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3376489/