本文介绍了动态google-code-prettify不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按钮是否可以调用一个能够美化动态< code>< pre> 的功能?我无法让它工作。

Is it possible for a button to call a function that would 'prettify' a dynamic <code><pre>? I can't get it to work.

页面加载后,初始< code> 被美化(?),但是当我更改它并之后调用prettyPrint()时,它不再有效。

After the page loads, the initial <code> is prettified(?), but when I change it and call prettyPrint() afterwards, it no longer works.

示例:

编辑:对不起,我使用的是本地的prettify.js 。更新了它,仍然遇到了同样的错误。

Sorry, I was using a local prettify.js. Updated it, still encountered the same error.

推荐答案

显然在代码被美化后,会添加一个额外的类,即 prettyprinted 。任何具有 prettyprinted 类的东西都不会被重新美化。您需要在调用函数之前删除该类:

Apparently after the code is prettified, an additional class is added which is prettyprinted. Anything with the class of prettyprinted is not re-prettified. You need to remove that class before recalling the function:

$('input[type=button]').click( function() {
    $("#jsExample").text("    var user = 'private'; //Do NOT store your API Key on a script.")
        .parent().removeClass("prettyprinted");

   prettyPrint();
});

这篇关于动态google-code-prettify不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:25