欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

简单的切换网页版本

程序员文章站 2022-06-11 10:45:00
...
跳至
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<style>
header {
    text-align: right;
}
#change-feeling {
    text-decoration: none;
    font-size: small;
}
#form-section {
    text-align: center;
    margin-top: 1em;
    padding-top: 100px;
}
#input {
    width: 40em;
    padding: 0.5em 0.2em;
    font-size: large;
}
</style>
<script>
function changeFeeling(feeling) {
    var now = new Date();
    var nextYear = new Date(now.getTime() + 3600000 * 24 * 365);
    document.cookie = 'feeling=' + feeling + '; expires=' + nextYear.toGMTString();
    
    location.reload();
}

</script>
</head>
<body>
<header>
<?php
if (array_key_exists('feeling', $_COOKIE)) {
    $feeling = $_COOKIE['feeling'];
} else {
    $feeling = 'old';
}

if ($feeling === 'new') {
    echo <<<EOT
<style class="feeling">
body {
    background: #80E0F0;
}
#input {
    height: 2em;
    font-family: "微软雅黑";
}
</style>
<a id=change-feeling href="javascript:changeFeeling('old');">返回旧版</a>
EOT;
} else {
    echo <<<EOT
<a id=change-feeling href="javascript:changeFeeling('new');">使用新版</a>
EOT;
}
?>
</header>
<section id=form-section>
<input id=input>
</section>
</body>
</html>