我在CMS中使用codepress来编辑文件系统中的文件。一切都运行良好,但是当尝试使用jQuery load()函数加载相同的页面时,codepress似乎破了。
我的javascript代码看起来像加载带有codpress的php文件,但是codepress似乎没有激发。
$('.content').on('click', '#fileSystemWrap a', function (event) {
event.preventDefault();
var fileName = $(this).data('file');
$('#rightColWrap').fadeOut(150, function(){
$('#rightColWrap').load('/?url=developer/edit-file.php&open=' + fileName, function(){
$('#rightColWrap').fadeIn(150);
});
});
});
深入研究codepress.js我在文件的末尾看到了这一点,但我不明白是否有什么东西可以添加到我的点击事件列表器脚本中,以帮助压制火灾。
if(window.attachEvent) window.attachEvent('onload',CodePress.run);
else window.addEventListener('DOMContentLoaded',CodePress.run,false);
这是sourceforge上codepress的链接 https://sourceforge.net/projects/codepress/
答案 0 :(得分:7)
要成为逻辑:加载数据时,我们要初始化CodePress。 所以你的代码应该是这样的:
$('.content').on('click', '#fileSystemWrap a', function (event) {
event.preventDefault();
var fileName = $(this).data('file');
$('#rightColWrap').fadeOut(150, function(){
$('#rightColWrap').load('/?url=developer/edit-file.php&open=' + fileName, function(){
CodePress.run();
$('#rightColWrap').fadeIn(150);
});
});
});
如果这不起作用,请从控制台提供错误。
编辑:纠正的答案,见过RobsonFrança的评论。
最后一个问题是CodePress.run;
应该写成CodePress.run();
答案 1 :(得分:0)
答案是我们需要在CodePress.run和fadeIn()调用之后添加括号。
$('#content').on('click', '#fileSystemWrap a', function (event) {
event.preventDefault();
var fileName = $(this).data('file');
$('#content').fadeOut(150, function(){
$('#content').load('/?url=developer/edit-file.php&open=' + fileName, function(){
$('#content').fadeIn(150, function(){
CodePress.run();
});
});
});
});