ajax資料定時自動儲存方法
window.onload=function(){
var txtobj = document.getelementbyid('txt1');
var spanobj = document.getelementbyid('s1');
//自動儲存
txtobj.addbehavior("#default#userdata");
var savetimer= setinterval(function(){
txtobj.setattribute('ovalue',txtobj.value);
txtobj.save('saveddata');
spanobj.innertext='資料儲存於:'+(new date());
settimeout(function(){
spanobj.innertext='';
},1000);
},10000); //每分鐘儲存一次
document.getelementbyid('btn1').attachevent('onclick',function(){
clearinterval(savetimer); //取消儲存
txtobj.removeattribute('ovalue');
});
document.getelementbyid('btn2').attachevent('onclick',function(){
txtobj.load('saveddata');
alert(txtobj.getattribute('ovalue'));
//txtobj.value = txtobj.getattribute('ovalue');
});
};
</script>
</head>
<body>
<span id="s1" style="color:red;"></span>
<p />
<textarea height="500" style="height:500px;width:500px;" id="txt1">
</textarea>
<p />
<input type="button" id="btn1" value="停止儲存" />
<input type="button" id="btn2" value="擷取儲存的值" />
</body>
</html>