⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.html

📁 javascript中也有自己的session机制
💻 HTML
字号:
<input type="text" id="txt">
<input type="button" id="btn" value="save" onclick="Session.save('txt','value','op');">
<input type="button" id="btn1" onclick="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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -