我有这个 JavaScript(带有 jQuery):
var g_files_added, socket, cookie, database = null;
var file_contents = [];
function viewFile(key, filename) {
$('#title-filename').text(filename);
$('.prettyprint').text(file_contents[key]);
$('#viewFileModal').modal('show');
}
$(document).ready(function() {
$(document).on('shown', '#viewFileModal', function(event) {
prettyPrint();
});
});
// Variables have been set in code not shown, irrelevant to problem.
// prettyPrint() is called everytime the #viewFileModal is shown,
// but its effect is only felt once.
prettyPrint()
每次显示 viewFileModal 模态框(由 Bootstrap 提供)时都会调用它,只是它似乎在每次页面加载时只产生一次效果。
prettyPrint()
在使模态框出现后,我尝试在 JS 控制台中注释并输入。它确实只在第一次显示该框时(每页加载)才有效。
有任何想法吗?我一直坚持这一点。我也试过把电话打到prettyPrint()
放在 viewFile 函数中;但效果是一样的。
非常感谢。
山姆。