我试图做一个从一个页面到另一个页面的链接,在链接本身上我发送了一个接收页面使用 php 获取的变量,然后我需要 php 回显 js 以更改两个 div 上的 css 显示,更改默认 css 为 block 的 div 为 hidden,第二个 div 的默认 css 为 none 为 block。我已经成功地在 url 中传递了变量,并且 js 将第二个 div 更改为阻止工作,但是第一个 div css 似乎没有更改为 none,因为 div 仍然显示
PHP代码
if (isset($_GET['display'])) {
if(!isset($_GET['yes'])) {
echo '<style type="text/css">
#slideshow {
display: none;
}
</style>';
echo '<style type="text/css">
#aboutus {
display: block;
}
</style>';
}
}else{
};
谁能帮我解决这个问题
最佳答案
你确定你不是这个意思:
if($_GET['display'] == 'yes') {
我会传递一个整数值而不是"is"和“否”。
然后这样做:
<?php
ob_start("ob_gzhandler");
header('Content-Type: text/html; charset=utf-8');
header('Connection: Keep-Alive');
header('Keep-Alive: timeout=5, max=100');
header('Cache-Control: max-age=84600');
header('Vary: Accept-Encoding');
echo <<<EOT
<!DOCTYPE html>
<html lang="en"><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>page Title</title>
<style type="text/css">
.hide{display:none;}
</style>
</head><body><div id="page">
EOT;
ob_flush();
$display = inval($_GET['display']);
$aboutclass = array(' class="hide" ','');
$slideclass = array('',' class="hide" ');
echo '<div id="aboutus" ' . $aboutclass [$display] . '>'
echo '<div id="slideshow" ' . $slideclass [$display] . '>'
echo '</div></body></html>';
ob_end_flush();
关于javascript - 使用 php 更改 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995748/