最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamic google-code-prettify doesn't work - Stack Overflow

programmeradmin1浏览0评论

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: /

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

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.

Share Improve this question edited Apr 13, 2013 at 3:46 GaiusSensei asked Apr 13, 2013 at 3:27 GaiusSenseiGaiusSensei 1,8904 gold badges27 silver badges45 bronze badges 1
  • Did you look at the console? It pretty explicitly tells you, prettyPrint is not defined for me. This may have to do with the fact that one of your scripts, prettify.js, is 404ing. – Xymostech Commented Apr 13, 2013 at 3:34
Add a comment  | 

1 Answer 1

Reset to default 19

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/

发布评论

评论列表(0)

  1. 暂无评论