我的网站在动态 CSS 更改的单个页面上运行。如果我想将客户端定向到页面内容,我所做的就是提供带有传递 CSS id 的页面链接。即:www.ilstours.net/index.php?css=1
索引.php:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/<?php echo $css; ?>.php" />
</head>
<body>
<button id="button1" type="button" onclick="index.php?css=2">Update</button> 'HERE
</body>
</html>
1.php:
<?php
header("Content-type: text/css; charset: UTF-8");
$Color = "black";
?>
body {background-color:<?php echo $Color ?>;}
2.php:
<?php
header("Content-type: text/css; charset: UTF-8");
$Color = "red";
?>
body {background-color:<?php echo $Color ?>;}
如何在单击按钮时切换到 CSS 文件 2.php?
最佳答案
index.php
<?php
$css = 1; // default css (1)
if(isset($_REQUEST['css']) && ($_REQUEST['css']==1 || $_REQUEST['css']==2))
{
$css = $_REQUEST['css']; // update by click on button (1 or 2)
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/<?php echo $css; ?>.php" />
</head>
<body>
<button id="button1" type="button" onclick="location.href='index.php?css=1';">Update CSS 1</button>
<button id="button1" type="button" onclick="location.href='index.php?css=2';">Update CSS 2</button>
</body>
</html>
关于PHP - 动态更改变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21845667/