Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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
google prettify无法在从jquery加载调用的块中工作_Jquery_Html - Fatal编程技术网

google prettify无法在从jquery加载调用的块中工作

google prettify无法在从jquery加载调用的块中工作,jquery,html,Jquery,Html,我是jquery的初学者,这个问题可能反映了我的无知。当我从本地的Prettify副本调用Google代码Prettify时,我遇到了一个问题(也就是说,我正在使用 <script type="text/javascript" src="localpath/prettify.js"></script> 而不是 <script src="https://google-code-prettify.googlecode.com/svn/loader/run_pret

我是jquery的初学者,这个问题可能反映了我的无知。当我从本地的Prettify副本调用Google代码Prettify时,我遇到了一个问题(也就是说,我正在使用

<script type="text/javascript" src="localpath/prettify.js"></script>

而不是

<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> 

(在这种情况下,问题消失)在我的html头标记中。问题如下:

如果我把

<pre class="prettyprint linenums">
print "test1\n";
print "test2\n";
print "test3\n";
</pre>

打印“test1\n”;
打印“test2\n”;
打印“test3\n”;
在主html文件中,它可以正常工作。但是,如果我尝试使用jquery load将辅助html文件加载到主html文件中,则辅助html文件中的预处理代码的样式不正确(行号和关键字未显示)。具体而言,我已将其放在我的InMy html head标记中:

<script>
  $(document).ready(function() 
  {
    $('#my_element').load('my_element.html');
    prettyPrint();
  });
</script>

$(文档).ready(函数()
{
$('#my_element').load('my_element.html');
预打印();
});
my_element.html的代码块与主html文件中的代码块完全相同:

<pre class="prettyprint linenums">
print "test1\n";
print "test2\n";
print "test3\n";
</pre>

打印“test1\n”;
打印“test2\n”;
打印“test3\n”;
它被加载到id==“my_element”的div标记中;但是,它在主页上的样式设置不正确。为什么?

prettyPrint()
在加载内容之前运行,这是由于
load
调用的异步性质,请尝试将其放置在回调中:

$('#my_element').load('my_element.html', function() {
    prettyPrint();
});

nt prettify附带了一个相应的css文件,您在本地使用时也会专门加载该文件?