Skip to content

Instantly share code, notes, and snippets.

@zsmynl
Created February 10, 2014 08:39
Show Gist options
  • Save zsmynl/8912387 to your computer and use it in GitHub Desktop.
Save zsmynl/8912387 to your computer and use it in GitHub Desktop.
使用localStorage保存页面内容。
/* 保存填写内容 begin */
<script type="text/javascript">
function saveMyContent(){
if(window.localStorage){
var items=["bugtitle","description","editor_content","editor_content1","editor_content2","usertags"];
$.each(items,function(k,v){
var inputValue=$("#"+v).val();
if (inputValue==null ||inputValue==""){
inputValue="";
}else{
inputValue=$("#"+v).val();
}
localStorage.setItem(v,inputValue);
});
}
}
function restoreMyContent(){
if(window.localStorage){
var items=["bugtitle","description","editor_content","editor_content1","editor_content2","usertags"];
$.each(items,function(k,v){
var inputStorageValue=localStorage.getItem(v);
if(inputStorageValue==null||inputStorageValue==""){
$("#"+v).val("");
}else{
$("#"+v).val(localStorage.getItem(v));
}
});
}
}
saveContentInt=setInterval(saveMyContent,10000);
$(function(){
restoreMyContent();
});
</script>
/* 保存填写内容 end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment