我正在尝试创建一个and应用程序,并在周围搜索以查找教程...我找到了"jquery“,并注意到当我查看代码时,没有单一的网站,只有一些div创建了单一的网站……这是怎么做到的呢?当我用div创建一个网站时,它们都在一个网站上。
谢谢
发布于 2012-07-24 23:47:48
你要做的就是识别出url中的hash标签后面是什么文本,并相应地显示/隐藏特定的div。
您可以使用jQuery轻松完成此操作。下面是我写的一个非常粗略的例子,但应该能让你对我所说的有一个概念。
index.html#home将显示“来自第1页的内容”
index.html#about将显示“来自第二页的内容”
<!DOCTYPE HTML>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
</head>
<body>
<div id="home_content_div" class="content_divs">
Content from page 1
</div>
<div id="about_content_div" class="content_divs">
Content from page 2
</div>
<script>
var identifier = window.location.hash;
$(".content_divs").hide();
if (identifier === "#home") {
$("#home_content_div").show();
}
else if (identifier === "#about") {
$("#about_content_div").show();
}
</script>
</body>
</html>https://stackoverflow.com/questions/11633556
复制相似问题