gpt4 book ai didi

javascript - 如何根据页面名称触发 div

转载 作者:行者123 更新时间:2023-11-28 15:35:28 26 4
gpt4 key购买 nike

如何根据页面名称触发 div。

我想根据页面名称在同一个 div 中显示不同的 php 响应。

我在想:

<?php

$pageName = basename($_SERVER['PHP_SELF']);
if ($pageName == 'index.php') {
include("http://website/reponse-from-script-1);
} else if ($pageName == 'index2.php') {
include("http://website/reponse-from-script-2);
} else if ($pageName == 'index3.php') {
include("http://website/reponse-from-script-3);
}

?>

这是因为所有页面的结构都是:

<html lang="en">
<head>
<?php include("includes/head.php");?>
</head>
<body>
<?php include("includes/top");?>

<div id= content>
<?php include("includes/content.php");?>
</div>

<?php include("includes/footer");?>
</body>
</html>

我想将此结构用于所有页面,并且我希望 div“内容”根据页面标题进行更改。

我们将不胜感激。

谢谢

--------更新 2----------这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<?php include("includes/head.php");?>
</head>
<body>
<?php include("includes/scripts.php");?>
<div id="wrapper">
<?php include("includes/navandsidebar.php");?>
<?php include("includes/main-menu.php");?>
<?php include("includes/secondary-menu.php");?>
<?php include("includes/working-space.php");?>

</div>
</body>
</html>

此代码适用于除这 2 个部分更改之外的所有页面,这就是为什么我想“在内部”触发 div。

   <?php  include("includes/secondary-menu.php");?>
<?php include("includes/working-space.php");?>

最佳答案

其实,从效率的 Angular 来看,你可以只用一个页面而不是多个页面,只需更改内容div,如下所示:

an_index.php:

 <?php
include("getContent.php");
echo "<a href=\"./an_index.php?page=$page\">next</a>";
?>

getContent.php:

<?php
$page = htmlentities($_GET['page']);
if (is_numeric($page)) {

include("http://localhost/exp/dyn_content.php?page=$page");
$page++;
if ($page > 3) {
$page = 1;
}

}

动态内容.php:

<?php
$p = htmlentities($_GET["page"]);
if (is_numeric($p))
{
switch($p) {
case 1:
echo "one<br>\n";
break;
case 2:
echo "two<br>\n";
break;
case 3:
echo "three<br>\n";
break;
default:
echo "one<br>\n";
break;
}
}

动态内容脚本当然可以用来从数据库中提取内容。注意:此解决方案依赖于允许 allow_url_include = On 的 PHP .INI 配置,这会在共享 服务器上出现安全问题。

关于javascript - 如何根据页面名称触发 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44208316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com