Javascript 如何根据页面名称触发div
如何根据页面名称触发div 我想根据页面名称在同一个div中显示不同的php响应 我的想法是:Javascript 如何根据页面名称触发div,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,如何根据页面名称触发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') {
<?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);
}
?>
实际上,从效率的角度来看,您可以只使用一个页面而不是多个页面,只需更改content 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
$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;
}
}
你可以使用\uuuuu FILE\uuuuu
这是一个神奇的常数好吧,我从来没有用过这个,所以我会看看它。感谢您上述解决方案是对原始发布问题的回应。由于问题显然更为复杂,您可能需要使用不同的模板以及在数据库中存储内容。主要原则是,您使用的模板和从数据库检索到的内容将基于给定网页URL的查询字符串。是的,您的答案对我很有用。非常感谢你。无论如何,我会选择将模板与php smarty引擎结合使用的解决方案,我认为这是最适合我使用的
<?php
include("getContent.php");
echo "<a href=\"./an_index.php?page=$page\">next</a>";
?>
<?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
$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;
}
}