Python-100-Days/Day61-65/code/project_of_tornado/assets/js/theme.js

28 lines
629 B
JavaScript

var saveSelectColor = {
'Name': 'SelcetColor',
'Color': 'theme-black'
}
// 判断用户是否已有自己选择的模板风格
if (storageLoad('SelcetColor')) {
$('body').attr('class', storageLoad('SelcetColor').Color)
} else {
storageSave(saveSelectColor);
$('body').attr('class', 'theme-black')
}
// 本地缓存
function storageSave(objectData) {
localStorage.setItem(objectData.Name, JSON.stringify(objectData));
}
function storageLoad(objectName) {
if (localStorage.getItem(objectName)) {
return JSON.parse(localStorage.getItem(objectName))
} else {
return false
}
}