简体   繁体   English

Django/JavaScript 按钮单击显示值 - 重新加载页面删除值

[英]Django/JavaScript button click shows value - reload page removes value

I'm creating a game in Django more specifically in oTree with a Django Template Language and JavaScript frontend.我正在使用 Django 模板语言和 JavaScript 前端在 Django 中创建游戏,更具体地说是在 oTree 中。 When I click a button a value needs to be shown (got that covered) this is done with some JavaScript.当我单击一个按钮时,需要显示一个值(覆盖),这是通过一些 JavaScript 完成的。 But when I refresh/reload the page I need that value to still be displayed and not click the button all over.但是当我刷新/重新加载页面时,我需要该值仍然显示,而不是全部单击按钮。 Does anybody know if there is a workaround for this in either Django or JavaScript?有人知道 Django 或 JavaScript 中是否有解决方法吗?

The state of the show/hidden values must be stored somewhere: either client-side (browser) or server-side.显示/隐藏值的 state 必须存储在某处:客户端(浏览器)或服务器端。 For client-side storing, you can use localStorage , for server-side - session , DB or cache .对于客户端存储,您可以使用localStorage ,对于服务器端 - sessionDBcache If you decide to use server-side state - add some more js to buttons onclick event handlers and send state of the button to the server by ajax If you decide to use server-side state - add some more js to buttons onclick event handlers and send state of the button to the server by ajax

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

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