javascript - How to restore html form
扔个三星炸死你
扔个三星炸死你 2017-06-30 09:55:18
0
3
732

Suppose I have a form

<form>
<input name="username"/>
</form>

Now when the user enters the username, the second time the user comes to the page again, the username has been obtained from the server. How can the input on the page display the username that the user has entered

扔个三星炸死你
扔个三星炸死你

reply all(3)
淡淡烟草味

Two solutions
Backend: Get the data from the backend and assign it to the input
Frontend: Save the input value to local cookie or localStorage

滿天的星座

The first one

Server

$_SESSION['username'] = $_POST['username'];

Template

<input name="username" value ="<?=$_SESSION['username']?>"/>

Second type

Refer to the comment function of this blog website. After the user enters the user name and email address for the first time comment, localstorage caches it. Next time, the cache is directly read and assigned to the value of the form

https://blog.codefun.cn/blog/...

習慣沉默

Aren’t your inputs stored in the background data? Page loading request data.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template