如何使用php从localstorage获取css值?

时间:2016-10-06 14:40:41

标签: javascript php html css local-storage

当我更改背景颜色时,我将名称颜色保存到localstrog,当我重新加载页面必须$ value从javascript获取名称颜色并以css样式显示 看我的代码来理解我的问题

<html>
<head>
<script>
    function chc(gv){
        if(gv=="red"){
            document.getElementById("main").style.backgroundColor="red";
            localStorage['mysave']="red"; 
        }
        else if(gv=="green"){
            document.getElementById("main").style.backgroundColor="green";
            localStorage['mysave']="green"; 
        }
     }
</script>

<!--now php get data from localstrog by javascript-->
<?php  $value = "<script type='text/javascript'>document.write(localStorage.mysave);</script>"; ?>

<style>
    #main{
        width: 200px;
        height: 100px;
        background-color:<?php echo $value; ?>;
    }
</style>

</head>
<body>
    <button onclick="chc('red')">red</button> <button     onclick="chc('green')">green</button>
    <div id="main">
        testing
    </div>
    <h3>reload page the php dont get data from localstrog and no display ni style</h3>
</body>
</html>

0 个答案:

没有答案