简体   繁体   English

Localstorage 错误,最好的纠正方法是什么?

[英]Localstorage mistake, best way to correct?

I am still abit of a noob and I made a site with an admin panel where I made the option to change the price showed on the front page.我仍然是个菜鸟,我创建了一个带有管理面板的网站,在那里我可以选择更改首页上显示的价格。 However I have made this with Localstorage and it works great but it probably wont show for other visitors right?但是我用 Localstorage 做了这个,效果很好,但它可能不会显示给其他访问者,对吧?

My current Localstorage code:我当前的本地存储代码:

<script>
             function save(){
            var gpprice = document.getElementById('gpvalue').value;
            localStorage.setItem("price", gpprice);
             }

    </script>

    <script>
             function save3(){
            var gpprice3 = document.getElementById('gpvalue3').value;
            localStorage.setItem("price3", gpprice3);
             }

    </script>

And to display it on the front page:并将其显示在首页上:

            <script>
                window.onload = function() {
                    document.getElementById("product-price1").innerHTML = "$" + localStorage.getItem('price') + "/M"; 
                    document.getElementById("product-price2").innerHTML = "$" + localStorage.getItem('price3') + "/M"; 
                    }
            </script>

It works really good for me and I would like a similar system.它对我很有用,我想要一个类似的系统。

So I guess my question is how can I correct this oopsie?所以我想我的问题是如何纠正这个 oopsie? Should I use MySQL instead to store the value?我应该使用 MySQL 来存储值吗? Or is there a way to still use this?或者有没有办法仍然使用它?

No one else can access your localstorage data.没有其他人可以访问您的本地存储数据。 You need to store it in a database.您需要将其存储在数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM