//Session类
function Session()
{
var SessionObj = null;
this.init = function()
{
SessionObj = document.createElement('input');
SessionObj.type = "hidden";
SessionObj.id = "Sessionid";
SessionObj.style.behavior = "url('#default#userData')"
document.body.appendChild(SessionObj);
}
this.load = function(sessionName)
{
if (sessionName != null && sessionName != "")
{
SessionObj.load("s");
return SessionObj.getAttribute(sessionName);
}
}
this.save = function(objId,attribute,sessionName)
{
var obj = null;
if (document.getElementById(objId) != null) obj = document.getElementById(objId)
else return;
var value = obj[attribute];
if (sessionName != null && sessionName != "")
{
SessionObj.setAttribute(sessionName,value)
SessionObj.save("s")
}
}
this.init();
}
var Session = new Session();
//例子:
在文本框中输入任意内容!!点击 [save] !!<br>
然后刷新页面!!也可以删除文本框内容!!! 点击[load] <br><br>
<input type="text" id="txt">
<input type="button" id="btn" value="save" οnclick="Session.save('txt','value','op');">
<input type="button" id="btn1" οnclick="alert(Session.load('op'));" value="load">
<script>
function Session()
{
var SessionObj = null;
this.init = function()
{
SessionObj = document.createElement('input');
SessionObj.type = "hidden";
SessionObj.id = "Sessionid";
SessionObj.style.behavior = "url('#default#userData')"
document.body.appendChild(SessionObj);
}
this.load = function(sessionName)
{
if (sessionName != null && sessionName != "")
{
SessionObj.load("s");
return SessionObj.getAttribute(sessionName);
}
}
this.save = function(objId,attribute,sessionName)
{
var obj = null;
if (document.getElementById(objId) != null) obj = document.getElementById(objId)
else return;
var value = obj[attribute];
if (sessionName != null && sessionName != "")
{
SessionObj.setAttribute(sessionName,value)
SessionObj.save("s")
}
}
this.init();
}
var Session = new Session();
</script>