Copy codeThe Code is as follows: <input type = text id = a> <button onclick = "Session. save ('A',. value); "> <button onclick =" alert (Session. load ('A') ">
<Body>
<Script language = "JavaScript">
<! --
Var Session = {
Isinit: false,
Init: function (){
SessionObj = document. createElement ('input ');
SessionObj. type = "hidden ";
SessionObj. id = "Sessionid ";
SessionObj. style. behavior = "url ('# default # userdata ')"
Document. body. appendChild (SessionObj );
This. isinit = true;
},
Save: function (sessionName, value ){
This. isinit? '': This. init ();
If (sessionName! = Null & sessionName! = ""){
SessionObj. setAttribute (sessionName, value)
SessionObj. save ("s ")
}
},
Load: function (sessionName ){
This. isinit? '': This. init ();
If (sessionName! = Null & sessionName! = ""){
SessionObj. load ("s ");
Return SessionObj. getAttribute (sessionName );
}
}
}
// -->
</SCRIPT>
The following is an article by other netizens:
Js stores a large amount of data.
The IE series is stored on the computer until files are deleted.
If FF is disabled, delete it.Copy codeThe Code is as follows: <script>
// UserData class
Var RuserData = {
O: null,
TimeExpires: 7,
Browser :'',
// Initialize userdata
Init: function ()
{
If (this. browser! = '')
Return true;
If (window. ActiveXObject) // for IE {
Try {
This. o = document. createElement ("input ");
This. o. id = "Ruserdata ";
This. o. type = "hidden ";
This. o. style. behavior = "url (# default # userData )";
This. browser = 'ie ';
Document. body. appendChild (this. o );
Return true;
} Catch (e) {return false ;}
} Else if (window. sessionStorage) // FF 2.0 + */
{
Try {
This. o = window. sessionStorage;
This. browser = 'ff ';
Return true;
} Catch (e) {return false ;}
}
Return false;
},
SetVal: function (key, val, timeout/* defines the time-out period. The default value is null */){
This. init ();
If (this. browser = 'ie '){
Try {
This. o. load (key );
This. o. expires = typeof timeout = 'undefined '? This. getTimeLimit (this. timeExpires): this. getTimeLimit (timeout );
This. o. setAttribute ('value', val );
This. o. save (key );
Return true;
} Catch (e) {return false}
} Else if (this. browser = 'ff '){
Try {this. o. setItem (key, val); return true ;}
Catch (e) {return false}
}
},
GetVal: function (key ){
This. init ();
If (this. browser = 'ie '){
Try {
This. o. load (key );
Return this. o. getAttribute ('value ');
} Catch (e) {return false ;}
} Else if (this. browser = 'ff '){
Try {return this. o. getItem (key );}
Catch (e) {return false}
}
},
DelVal: function (key ){
This. init ();
If (this. browser = 'ie '){
Try {
This. o. load (key );
This. o. expires = new Date (315532799000). toUTCString ();
This. o. save (key );
Return true;
}
Catch (e) {return false ;}
} Else if (this. browser = 'ff '){
Try {this. o. removeItem (key); return true ;}
Catch (e) {return false}
}
},
GetTimeLimit: function (days/* set timeout days */){
Var d = new Date ();
D. setDate (d. getDate () + days );
Return d. toUTCString ();
}
};
Window. onload = function (){
// Alert (RuserData. delVal ('renchuno '));
// Alert (RuserData. setVal ('renchun', 'foot home www.jb51.net '));
Alert (RuserData. getVal ('renchuno '));
}
</Script>
Usage:Copy codeThe Code is as follows: window. onload = function (){
// Alert (RuserData. delVal ('renchuno '));
// Alert (RuserData. setVal ('renchun', 'foot home www.jb51.net '));
Alert (RuserData. getVal ('renchuno '));
}