很早期的东西

 1/*
 2 * Class Session
 3 * 在客户端多页面之间共享信息
 4 */

 5function Session()
 6{
 7    var SessionObj = null;
 8    this.init = function()
 9 {
10     SessionObj = document.createElement('input');
11  SessionObj.type = "hidden";
12  SessionObj.id = "Sessionid";
13  SessionObj.style.behavior = "url('#default#userData')" 
14        document.body.appendChild(SessionObj);
15 }

16   this.load = function(sessionName)
17 {
18     if (sessionName != null && sessionName != "")
19  {
20      SessionObj.load("s");
21   return SessionObj.getAttribute(sessionName);
22  }

23 }

24
25 this.save = function(objId,attribute,sessionName)
26 {
27      var obj = null;
28  if (document.getElementById(objId) != null) obj = document.getElementById(objId)
29  else return;
30     var value = obj[attribute];
31 
32        if (sessionName != null && sessionName != "")
33  {
34      SessionObj.setAttribute(sessionName,value)
35   SessionObj.save("s")
36     }

37 }

38
39 this.init(); 
40}

41var Session = new Session();
42
43
44//例子:
45
46在文本框中输入任意内容!!点击 [save] !!<br>
47然后刷新页面!!也可以删除文本框内容!!! 点击[load] <br><br>
48<input type="text" id="txt">
49<input type="button" id="btn" value="save" onclick="Session.save('txt','value','op');">
50<input type="button" id="btn1" onclick="alert(Session.load('op'));" value="load">
51
52<script>
53function Session()
54{
55    var SessionObj = null;
56    this.init = function()
57 {
58     SessionObj = document.createElement('input');
59  SessionObj.type = "hidden";
60  SessionObj.id = "Sessionid";
61  SessionObj.style.behavior = "url('#default#userData')" 
62        document.body.appendChild(SessionObj);
63 }

64   this.load = function(sessionName)
65 {
66     if (sessionName != null && sessionName != "")
67  {
68      SessionObj.load("s");
69   return SessionObj.getAttribute(sessionName);
70  }

71 }

72
73 this.save = function(objId,attribute,sessionName)
74 {
75      var obj = null;
76  if (document.getElementById(objId) != null) obj = document.getElementById(objId)
77  else return;
78     var value = obj[attribute];
79 
80        if (sessionName != null && sessionName != "")
81  {
82      SessionObj.setAttribute(sessionName,value)
83   SessionObj.save("s")
84     }

85 }

86
87 this.init(); 
88}

89var Session = new Session();
90</script>
91
posted on 2006-11-01 09:54  安森  阅读(1386)  评论(0)    收藏  举报