How to stop a variable from being destroyed on pressing F5 in javascript
问题 I have the following code <html> <head> <script> var m=0; function add() { m++; } </script> </head> <body> <button onclick="add();">click</button> </body> </html> But if I refresh the page then again the value of m starts from 0. How can I persist the value of m between each load of the page on a client machine? 回答1: you can use cookies from javascript. check this link. http://www.w3schools.com/js/js_cookies.asp here is the working code sample: <html> <head> <script> var m=getCookie("m"); if