我有一个页面,其中包含许多包含不同类型信息的页眉。此页面是对与特定主题有关的所有信息的整合。我们有许多其他页面应单独显示这些单独的标题,但不显示所有这些页面(类似于iframe,但没有全部页面内容)。将HTML内容从一个页面提取到另一个页面
有没有一种方法可以设置合并页面,其中一些ID将被其他页面单独拉出,因此只显示单个ID中的内容?
我用以下来测试一个jQuery方法。
内容页
<html>
<head><title>page 1</title></head>
<body>
<div id="info1">
This is DIV 1 info.
</div>
<div id="info2">
This is DIV 2 info.
</div>
</body>
</html>
检索页
<head>
<title>page 2</title>
<style>
body{ font-size: 12px; font-family: Arial; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
$("#info1").load("page1.htm");
</script>
<script>
$("#info2").load("page1.htm");
</script>
<b>Successful Response (should be blank):</b>
<div id="success"></div>
<b>Error Response:</b>
<div id="error"></div>
<script>
$("#success").load("/not-here.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
</script>
</body>
</html>
它的软件,当然有一种方法。唯一的问题是“如何?”和“它有多难?” – Sorpigal
为什么你不能在服务器端做到这一点? – Marcin
document.ready。学习它,爱它,使用它。 –