Dynamic google-code-prettify doesn't work

南楼画角 提交于 2019-11-26 16:54:38

问题


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

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

Example: http://jsfiddle.net/uwBjD/2/

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


回答1:


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();
});

http://jsfiddle.net/uwBjD/3/



来源:https://stackoverflow.com/questions/15983894/dynamic-google-code-prettify-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!