自闭症康复网,内容丰富有趣,生活中的好帮手!
自闭症康复网 > html 保存草稿 利用localStorage实现对ueditor编辑内容定时保存为草稿 ueditor草稿箱...

html 保存草稿 利用localStorage实现对ueditor编辑内容定时保存为草稿 ueditor草稿箱...

时间:2022-12-12 01:05:07

相关推荐

html 保存草稿 利用localStorage实现对ueditor编辑内容定时保存为草稿 ueditor草稿箱...

利用localStorage实现对ueditor编辑内容定时保存为草稿,ueditor草稿箱

直接看代码吧

1、引入ueditor和ueditor的使用我就不细说了 详情请戳/wangdianyong/article/details/39780709

2、ueditor.jsp

$(document).ready(function() {

var ue = UE.getEditor('container');

ue.addListener("ready", function() {

// editor准备好之后才可以使用

var html = localStorage.getItem("ctValue");

alert(html);

ue.setContent(html);

});

});

${param.content }

var ue = UE.getEditor('container');

localStorage.js

$(document).ready(

function() {

if (!window.localStorage) {

alert('您的浏览器不支持 localStorage 技术!');

} else {

// var spanObj = $("span");

// alert("spanObj" + spanObj);

var saveTimer = setInterval(

function() {

var str = "";

if (document.all) {/* IE */

str = document.frames[1].document.body.innerHTML;

} else {/* Chrome,ff */

// str =

// document.getElementById("container").contentDocument.body.innerHTML;

var ue = UE.getEditor('container');

str = ue.getContent();

}

if (str.length > 20

&& (str.indexOf("。") > -1 || str

.indexOf(",") > -1)) { /*

* 有内容才保存

* 且有句号或逗号

*/

localStorage.setItem("ctValue", str);

var d = new Date();

var YMDHMS = d.getFullYear() + "-"

+ (d.getMonth() + 1) + "-"

+ d.getDate() + " "

+ d.getHours() + ":"

+ d.getMinutes() + ":"

+ d.getSeconds();

// alert(YMDHMS);

// spanObj.innerHTML = '(数据保存于: ' +

// YMDHMS

// + ')';

//var text = $("span").text = '(数据保存于: '

//+ YMDHMS + ')';

$("#span").text('(数据保存于: ' + YMDHMS + ')');

//alert(text);

setTimeout(function() {

// spanObj.innerText = '';

}, 5000);

}

}, 25000); // 每隔N秒保存一次

function stoplocs() {

clearInterval(saveTimer); // 停止保存

// localStorage.removeItem("ctValue"); //清空

}

function showlocs() {

var html = localStorage.getItem("ctValue");

editor.setContent(html);

// alert(localStorage.getItem("ctValue"));

}

}

});

基本的定时保存为草稿的内容就实现了,你可关闭你的浏览器重新打开页面发现自己以前编辑的内容并没有因意外情况的出现而丢失。

源代码下载地址

/webzh/931800.true/webzh/931800.htmlTechArticle利用localStorage实现对ueditor编辑内容定时保存为草稿,ueditor草稿箱 直接看代码吧 1、引入ueditor和ueditor的使用我就不细说了 详情请戳http://...

如果觉得《html 保存草稿 利用localStorage实现对ueditor编辑内容定时保存为草稿 ueditor草稿箱...》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。