【发布时间】:2015-12-17 12:50:18
【问题描述】:
我试图通过在我的 NavBar 中选择链接时加载 DIV 标记来摆脱 FRAME 标记(用于加载“file1.html”target="ContentFrame")。我现在将单个页面分为两个 DIV 标记。顶部的 DIV 标记是我的导航栏,它可以完美地将 html 文件加载到 FRAME 中,但现在我尝试加载 HTML 文件(在删除所有额外的 HTML 标记,如 HTML、HEAD、BODY 等之后......)到第二个 DIV 标签称为“内容”。我研究了 jQuery .Load,但似乎无法让它像我想要的那样工作。我现在正在考虑研究 PHP。我真的很愿意接受关于寻找什么的建议,或者任何可能做我想做的事情的示例来源。有什么想法吗?
<!-- NavBar -->
<a href="body1.html">Load body1.html into DIV ID Content</a>
<a href="body2.html">Load body2.html into DIV ID Content</a>
<div id="Content">
Contents of body1.html would be here when page is first loaded.
Then the contents here would be loaded from the file in the anchor
tag when a link is selected. The bodyX.html files would have tags
within them as well. Not just text.
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function() {
$("a").click(function(e) {
e.preventDefault();
$("#Content").load(this.href, function(data, textStatus, jqxhr) {console.log(data, textStatus, jqxhr.status)})
})
.filter("[href=http://www.gddas.com/newsite/home.html]").click()
})
</script>
<title>Index Page</title>
</head>
<body>
<div class="header">
<img src="images/logos/GDDASLogo.png" width="274" height="133" alt="GDDAS Logo" /><br>
<ul class="flex">
<li><a href="home.html">Home</a></li> <!-- This had the full path, but that didn't make a difference -->
<li><a href="officers.html">Officers</a></li>
<li><a href="announce.html"</a>
<ul>
<li><a href="events.html">Events</a></li>
<li><a href="education.html">Continuing Ed</a></li>
</ul>
</li>
</ul>
</div>
<div class="content">
</div>
</body>
</html>
【问题讨论】:
-
显示您尝试过的代码。 .load() 是您正在寻找的解决方案