Home > front end >  The user to enter text input on the page, it is necessary to save to another page, and open there ne
The user to enter text input on the page, it is necessary to save to another page, and open there ne

Time:11-02

Every time I use the local store, but can only save one, because the user to enter a page, there is only one and I want to save to another page, with setitem and the getitem method are the same every time, I want to realize user input accumulation preservation, somewhat akin to save the text document, I now would be a main innerHTML dynamic insertion method, but can't forever and accumulative preservation, experience how to solve the bosses to help overcome? Thank you!!!

CodePudding user response:

enter
 
& lt; Input the id="t1" & gt; & lt; Button onclick="save ()" & gt; Save & lt;/button>
& lt; Script>
The function the save () {
Var t1=document. GetElementById (" t1 ")
Var mySave=localStorage [] "mySave"? JSON. Parse (localStorage [" mySave "]) : []
MySave. Push (t1) value)
LocalStorage [" mySave "]=JSON. Stringify (mySave)
t1.valuehttps://bbs.csdn.net/topics/=""
}
& lt;/script>


display page
 
& lt; Textarea id="t2" style="width: 600 px; Height: 400 px;"> & lt;/textarea> & lt; Button onclick="show ()" & gt; Display & lt;/button>
& lt; Script>
The function show () {
Var t2=document. GetElementById (" t2 ")
Var mySave=localStorage [] "mySave"? JSON. Parse (localStorage [" mySave "]) : []
T2. Value=https://bbs.csdn.net/topics/JSON.stringify (mySave, null, 4)
}
& lt;/script>

CodePudding user response:

Thank you I went back to try to solve

CodePudding user response:

Try using cookies

CodePudding user response:

reference big_shot reply: 3/f
try using cookies
is mainly used on app

CodePudding user response:

reference 1st floor cn00439805 response:
enter
 
& lt; Input the id="t1" & gt; & lt; Button onclick="save ()" & gt; Save & lt;/button>
& lt; Script>
The function the save () {
Var t1=document. GetElementById (" t1 ")
Var mySave=localStorage [] "mySave"? JSON. Parse (localStorage [" mySave "]) : []
MySave. Push (t1) value)
LocalStorage [" mySave "]=JSON. Stringify (mySave)
t1.valuehttps://bbs.csdn.net/topics/=""
}
& lt;/script>


display page
 
& lt; Textarea id="t2" style="width: 600 px; Height: 400 px;"> & lt;/textarea> & lt; Button onclick="show ()" & gt; Display & lt;/button>
& lt; Script>
The function show () {
Var t2=document. GetElementById (" t2 ")
Var mySave=localStorage [] "mySave"? JSON. Parse (localStorage [" mySave "]) : []
T2. Value=https://bbs.csdn.net/topics/JSON.stringify (mySave, null, 4)
}
& lt;/script>
?? , solved, later I will own to find a way to achieve results
  • Related