Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载页面后,prettyPrint()函数不起作用_Javascript_Syntax Highlighting_Google Code Prettify - Fatal编程技术网

Javascript 加载页面后,prettyPrint()函数不起作用

Javascript 加载页面后,prettyPrint()函数不起作用,javascript,syntax-highlighting,google-code-prettify,Javascript,Syntax Highlighting,Google Code Prettify,我正在通过CDN使用google code prettify,prettyPrint()的常见问题解答中提到的 是突出显示代码的函数。 现在我有问题了 prettyPrint() 当页面加载并突出显示语法时,cdn自动调用此函数,但在加载后,我正在更改代码的内容,然后我希望它再次突出显示。但我无法使用prettyPrint()函数实现这一点 我自己托管了googlecode prettify,然后我使用了prettyPrint(),它工作得很好,但当我在更改代码后调用此函数时,什么都没有发生,它

我正在通过CDN使用
google code prettify
prettyPrint()的常见问题解答中提到的

是突出显示代码的函数。
现在我有问题了

prettyPrint()
当页面加载并突出显示语法时,cdn自动调用此函数,但在加载后,我正在更改代码的内容,然后我希望它再次突出显示。但我无法使用
prettyPrint()
函数实现这一点

我自己托管了
googlecode prettify
,然后我使用了
prettyPrint()
,它工作得很好,但当我在更改代码后调用此函数时,什么都没有发生,它不会突出显示我的语法

这是我正在使用的代码


开发者查询
/*此CSS应用于用户正在访问的分区的按钮*/
ul#nav>li#btn2{
边框顶部:3px实心#FF9900;
左边框:2倍纯色灰色;
右边框:2倍纯色灰色;
底部边框:2件纯白;
边界半径:4px;
}
/*按钮CSS结束。*/
.内容{
宽度:1136px;
保证金:0px自动;
}
输入#问题(标题){
保证金:20px自动;
宽度:100%;
高度:20px;
}
text区域#问题_内容{
宽度:100%;
高度:300px;
保证金:0px自动;
}
#预演{
宽度:100%;
溢出:自动;
}
这是它的样子
html
//辅助函数//// 函数$(id){ 返回文档.getElementById(id); } 函数render(){// var问题内容=$(“问题内容”)。值; //清理数据// var授权={//所有Html实体的列表 '':"", “\n”:“
”, } question_content=question_content.replace(/|\n/gi,函数(html_ent){return authorizes[html_ent];}); var预览=$(“预览”); preview.innerHTML=问题内容; //预打印(); }
当运行
prettyprint()
时,它会将“prettyprinted”类添加到它更改的每个元素中。如果需要重新应用
prettyprint()
,请先删除“prettyprinted”类,然后调用
prettyprint()

请显示您的HTML,包括使用prettify的位置。这可能是一个DOM问题。用我的代码更新的问题我看不到你实际包含脚本的地方。您的代码中是否有
或类似内容?@andrewFan再次更新
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Developer Query</title>
<link href="css/header.css" rel="stylesheet" type="text/css">
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<style>
/*This CSS applied button in which section user is visiting. */
ul#nav > li#btn2 {
    border-top: 3px solid #FF9900;
    border-left: 2px solid grey;
    border-right: 2px solid grey;
    border-bottom: 2px solid white;
    border-radius: 4px;
}
/*Button CSS is end. */ 
.content{
    width:1136px;
    margin:0px auto;
}
input#question_title{
    margin:20px auto;
    width:100%;
    height:20px;
}
textarea#question_content{
    width:100%;
    height:300px;
    margin:0px auto;
}
#preview{
    width:100%;
    overflow:auto;
}
</style>
</head>

<body>
<?php include_once('php_include/header.php'); ?>
<div class="content">
    <input type="text" name="question_title" id="question_title" placeholder="What happed with your code?" />
    <textarea id="question_content" name="question_content" placeholder="Elabrote your code" onKeyUp="render();"></textarea>
    <h3>Here's what it look like</h3>
    <code class="prettyprint"><div id="preview">&lt;html&gt;</div></code>
    </div>
</body>
<script>
//HELPER FUNCTIONS////
function $(id){
    return document.getElementById(id);
}
function render(){//
    var question_content = $("question_content").value;
    //Sanitizing data//
    var entitles = {//List of all Html entitiles
        '<':"&lt;",
        '>':"&gt;",
        '\n':"<br>",        
    }
    question_content = question_content.replace(/<|>|\n/gi, function (html_ent){return entitles[html_ent];});
    var preview = $("preview");
    preview.innerHTML = question_content;   
    //prettyPrint();
}
</script>
</html>