開關(switch)狀態的緩存

給javascript增長一個classjavascript

function getCache() {
	var $link_cache = document.querySelector("#link-cache .mui-switch");
	var cache_status = plus.storage.getItem("cache_status");
	if (cache_status == '1') {
		$link_cache.className += "mui-active";
	}
	else if (cache_status == '0') {
		$link_cache.className = $link_cache.className.replace('mui-active', '');
	}
}

把開關的狀態記錄到緩存中java

document.getElementById("link-flow").addEventListener("toggle", function(event) {
	var isActive = event.detail.isActive;
	if(isActive) {
		plus.storage.setItem('flow_status', '1');
		plus.nativeUI.toast('開啓流量播放!');
	} else {
		plus.storage.setItem('flow_status', '0');
		plus.nativeUI.toast('關閉流量播放!');
	}
});

把開關狀態取出來並作判斷緩存

function getFlow() {
	var $link_flow = document.querySelector("#link-flow .mui-switch");
	var flow_status = plus.storage.getItem("flow_status");
	if (flow_status == '1') {
		$link_flow.className += "mui-active";
	}
	else if (flow_status == '0') {
		$link_flow.className = $link_flow.className.replace('mui-active', '');
	}
}
相關文章
相關標籤/搜索