我有一个页面(page.php),其内容是动态的(假设有3种不同的内容可用)。加载的内容取决于我们点击的菜单的哪个链接。我的问题是下一个:我在这个页面(page.php)上加载了contentA。我想说:
if (...){
<script>
location.href = "page.php";
$(".content-area").load("content-B.php");
</script>
}
我怎么能这样做? 谢谢!
答案 0 :(得分:1)
“location.href”将重新加载您的网页,导致javascript从该点开始停止执行。如果您想出于某种原因使用page.php重新加载页面,那么您可能会执行以下操作:
location.href =“page.php?content = b”
然后你可以在page.php中使用PHP来查找“内容”参数,并使用include或其他技术加载适当的内容。这样的东西会出现在你的page.php中:
if(isset($_GET["content"]) && trim($_GET["content"]) == 'a'){
include 'a.php';
} else if(isset($_GET["content"]) && trim($_GET["content"]) == 'b') {
include 'b.php';
} else if(isset($_GET["content"]) && trim($_GET["content"]) == 'c') {
include 'c.php';
} else {
include 'default.php';
}