Hello, tell me the script of saving data in input, for example, if you need to remember the text when the page is reloaded, which is in <input type="text" name="name">
|
3 answers
You can solve this problem using HTML5 LocalStorage . Based on the article: Storing Data the Simple HTML5 Way and using the jQuery framework (since I'm not strong in pure JS), this is what happened: http://jsfiddle.net/kzy2M/
- Thanks, and how to delete data from the repository? - ivanforpw
- localStorage.removeItem ('some_name'); - Deonis
|
You can also use cookies. I think a more convenient option.
- @ kal1sha, Try to write more detailed answers. Explain what your statement is based on. - Sleeping Owl
- @ kal1sha, udbney for whom and what? In both cases, use is a pair of lines. How to disable cookies - probably knows any student. How to disable Local Storage - they know much less people, and many may not even be aware of this method of data storage. Yes, can JS be disabled? In this case, nothing prevents the use of both methods. But, since Since all modern sites are built using JS anyway, it is unlikely that anyone will turn it off. - Deonis
|
Here is the Angular variation <if desired, you can redo it in JS
this.setStorage = function(key, value) { value = angular.toJson(value); localStorage.setItem(key, value); }; this.getStorage = function(key) { return JSON.parse(localStorage.getItem(key)); };
|