简体   繁体   English

保存到变量 JavaScript

[英]Saving to a variable JavaScript

I have a variable that can be added to with a button click, what I want to do is if one user clicks and adds 1 to the variable, it saves to the code and is viewable for everyone.我有一个可以通过单击按钮添加的变量,我想要做的是,如果一个用户单击并将 1 添加到变量中,它会保存到代码中并且可供所有人查看。 My code so far is到目前为止我的代码是

<div class="game-object">
    <script type="text/javascript">

        var clicks = 0;
        function updateClickCount() {
            document.getElementById("clickCount").innerHTML = clicks;
        }
    </script>
    <button type="button" class "myButton" onClick="clicks++;updateClickCount();" id="push">Press me !!!</button> <br>
    <p4> Number of presses: </p4>
    <div id="clickCount"></div>
</div>

I'm new to javascript so can someone please help:)我是 javascript 的新手,所以有人可以帮忙:)

Welcome to the platform !欢迎来到平台!

You need a database to persist the updated value of clicks variable.您需要一个数据库来保存 clicks 变量的更新值。 Without it, it is not possible to show the new value to every user.没有它,就不可能向每个用户展示新的价值。

Without database it is possible that each user can see the value, updated only by him/her (not by other users).如果没有数据库,每个用户都可以看到仅由他/她(而不是其他用户)更新的值。

Please, let me know which option is right for you and if you have a server and if you have one, what is the technology stack that you are using there on your server, so I can help you further.请让我知道哪个选项适合您,如果您有服务器,如果有,您在服务器上使用的技术堆栈是什么,以便我可以进一步帮助您。

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

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