【发布时间】:2026-02-23 20:25:02
【问题描述】:
我正在处理一个客户希望将现有页面动态加载到单个页面中的项目。这没问题,但是当页面在现有站点上作为独立文件加载时,样式无法正常工作。有没有办法从每个页面中提取 CSS 链接并将其动态应用于查看器页面?
这是我编写的将外部页面调用到查看器页面的函数的副本:
$(function () {
$('a.dock-item2').click(function () { // click on an anchor with the dock-item2 class
$("#page").remove(); // remove what's in the viewer already
var href = $(this).attr('href'); // grab the external file path and name
$('<div id="page" />').load(href, function () { // create a new div and load
// the page content
$(this).hide() // just stuff to make a nice transition...
.appendTo('#viewer')
.fadeIn(1000);
});
return false;
})
});
我想将它严格应用到有问题的 div 上……但也许这不是最好的做法。我应该考虑将这些东西加载到 iframe 中吗?可能只是星期五,我已经无法理性思考了。
【问题讨论】: