SyntaxHighlighter.all() 在 DOM 级别不起作用?
可能的重复:
jquery 加载问题
我正在使用 jQuery load() 函数将内容动态加载到 div 中。 在回调中我调用 SyntaxHighlighter.all(), 漂亮地打印刚刚加载到 div 中的 pre 块的语法。
问题是内容加载正常,但语法没有突出显示。 但是,当我对 div 中的 pre 块进行硬编码时,因此不通过 jQUery load() 函数加载到 DOM 中,语法 get 会按其应有的方式突出显示。
所以我猜测 SyntaxHighlighter.all() 只适用于 html 源代码中的预块,可以使用视图页面源代码进行查看,而不适用于 DOM 中的实际内容?
知道我怎样才能让它发挥作用吗?
执行加载和突出显示的 javascript:
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
$(document).ready(function() {
var tree = $("#tree li");
var contentContainer = $("#contentContainer");
var content = $("#content");
SyntaxHighlighter.config.clipboardSwf = 'syntaxhighlighter_2.0.320/scripts/clipboard.swf';
SyntaxHighlighter.all();
// Treeview
$("#tree").treeview({
persist: "location",
collapsed: true
});
tree.click(function() {
if ($(this).hasClass("file")) {
tree.removeClass("selected");
$(this).addClass("selected");
content.load("content/"+this.id+".html", function() {
contentContainer.effect("highlight");
SyntaxHighlighter.all();
});
}
});
});
</script>
内容 div:
<div id="content">
<pre class="brush: java;">
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
</pre>
</div>
使用 jQuery.load() 加载的外部文件:
Hello World
<pre class="brush: java;">
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
</pre>
亲切的问候
Possible Duplicate:
jquery load issue
I'm loading content dynamically into a div using the jQuery load() function.
In the callback I'm calling SyntaxHighlighter.all(),
to pretty print the syntax of the pre block that just got loaded into the div.
The problem is that the content is loaded OK, but the syntax doesn't get highlighted.
However, when I hardcode the pre block in the div, so not loading in into the DOM via the jQUery load() function, the syntax get's highlighted as it should.
So I'm guessing that the SyntaxHighlighter.all() only works on pre blocks that are in the html source, that can be viewed using view page source, and not on the actual content in the DOM?
Any idea how I can make it work?
The javascript to do the loading and highlighting:
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
$(document).ready(function() {
var tree = $("#tree li");
var contentContainer = $("#contentContainer");
var content = $("#content");
SyntaxHighlighter.config.clipboardSwf = 'syntaxhighlighter_2.0.320/scripts/clipboard.swf';
SyntaxHighlighter.all();
// Treeview
$("#tree").treeview({
persist: "location",
collapsed: true
});
tree.click(function() {
if ($(this).hasClass("file")) {
tree.removeClass("selected");
$(this).addClass("selected");
content.load("content/"+this.id+".html", function() {
contentContainer.effect("highlight");
SyntaxHighlighter.all();
});
}
});
});
</script>
the content div:
<div id="content">
<pre class="brush: java;">
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
</pre>
</div>
the external file that gets loaded with jQuery.load():
Hello World
<pre class="brush: java;">
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
</pre>
Kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案: jquery 加载问题
solution: jquery load issue