使用userdata保存客户端数据(从51js找到的)

从51js找到一些好东西,作个备忘

示例一:checkbox的使用

< style >
      .userData 
{behavior:url(#default#userdata);}
</ style >
< input type = checkbox id = chkbox1 class = userData >
< script >
var  obj = document.all.chkbox1;
obj.attachEvent('onclick',saveChecked)
function  saveChecked() {
obj.setAttribute(
"bCheckedValue",obj.checked);
obj.save(
"oChkValue");
}

window.attachEvent('onload',loadChecked)
function  loadChecked() {
obj.load(
"oChkValue");
var chk=(obj.getAttribute("bCheckedValue")=="true")?true:false;
obj.checked
=chk;
}

</ script >

示例二:文本框标记的应用

< HTML >
< HEAD >
< STYLE >
   .userData 
{behavior:url(#default#userdata);}
</ STYLE >
< SCRIPT >
function  fnSaveInput() {
   
var oPersist=oPersistForm.oPersistInput;
   oPersist.setAttribute(
"sPersist",oPersist.value); //将oPersist.value存储为sPersist属性
   oPersist.save("oXMLBranch");  //存储在名为oXMLBranch的UserData存储区
}

function  fnLoadInput() {
   
var oPersist=oPersistForm.oPersistInput;
   oPersist.load(
"oXMLBranch");  //载入在名为oXMLBranch的UserData存储区
   oPersist.value=oPersist.getAttribute("sPersist"); //将sPersist属性赋值给oPersist.value
}

</ SCRIPT >
</ HEAD >
< BODY >
< FORM ID = " oPersistForm " >
< INPUT CLASS = " userData "  TYPE = " text "  ID = " oPersistInput " >
< INPUT TYPE = " button "  VALUE = " Load "  onclick = " fnLoadInput() " >
< INPUT TYPE = " button "  VALUE = " Save "  onclick = " fnSaveInput() " >
</ FORM >
</ BODY >
</ HTML >



示例三:Select标记的应用

< style >
      .userData 
{behavior:url(#default#userdata);}
</ style >
< select id = " select1 "   class = " userData " >
< option > option1 </ option >
< option > option2 </ option >
< option > option3 </ option >
< option > option4 </ option >
</ select >
< script >
var  obj = document.all.select1;
obj.attachEvent('onchange',saveSelectedIndex)
function  saveSelectedIndex() {
obj.setAttribute(
"sSelectValue",obj.selectedIndex);
obj.save(
"oSltIndex");
}

window.attachEvent('onload',loadSelectedIndex)
function  loadSelectedIndex() {
obj.load(
"oSltIndex");
obj.selectedIndex
=obj.getAttribute("sSelectValue");
}

</ script >

你可能感兴趣的:(user)