我有这段代码
var editBtn = document.getElementById('editBtn');
var editables = document.querySelectorAll('#content');
if (typeof (Storage) !== "undefined") {
if (localStorage.getItem('content') !== null) {
editables[0].innerHTML = localStorage.getItem('content');
}
}
editBtn.addEventListener('click', function (e) {
if (!editables[0].isContentEditable) {
editables[0].contentEditable = 'true';
editBtn.innerHTML = 'Save Changes';
editBtn.style.backgroundColor = '#6F9';
} else {
// Disable Editing
editables[0].contentEditable = 'false';
// Change Button Text and Color
editBtn.innerHTML = 'Enable Editing';
editBtn.style.backgroundColor = '#F96';
// Save the data in localStorage
for (var i = 0; i < editables.length; i++) {
localStorage.setItem(editables[i].getAttribute('id'), editables[i].innerHTML);
}
}
});
除此之外我还需要一个函数(代码),这样我就可以将本地存储中的当前数据保存到数据库,并在我用不同的用户登录A / c后重置本地存储