How to make changes to HTML document permanent using Javascript?

前端 未结 3 1651
误落风尘
误落风尘 2021-01-13 14:16
  1. I have a simple like counter code, but the changes made disappear after the page is refreshed.

  2. Why does this happen, should this be done using PHP ?

3条回答
  •  孤城傲影
    2021-01-13 15:01

    The javascript is reloaded when the page is reloaded, so it's natural that the changes are lost as well.

    You can, however, store them permanently, either in a web service, or preferrably in localStorage. Then you can retrieve from localStorage on page load.

    Using PHP probably wouldn't help without storing it somewhere.

    I don't think your code could be written that much more efficient.

提交回复
热议问题