[英]How to enable local storage for cordova app
I am trying to store the values in to the local storage in an hybrid app. 我正在尝试将值存储在混合应用程序中的本地存储中。 When I run the app in desktop web browser, but when I run the same in the android device I am not able to see the same output as in web browser.
当我在桌面网络浏览器中运行该应用程序时,但在android设备中运行该应用程序时,却看不到与网络浏览器中相同的输出。 I think it's not getting saved in local storage.
我认为它没有保存在本地存储中。
Is there any way i can solve this or do i have to enable the local storage? 有什么办法可以解决此问题,还是必须启用本地存储?
Here's my code: 这是我的代码:
function deductBalance(){
var str;
var num_arr = [];
var elems = document.querySelectorAll('.cost-block-deduct');
elems.forEach(function(el) {
var nums = el.options[el.selectedIndex].value;
num_arr.push(nums)
});
console.log(num_arr);
var alvar1 = (Number.parseInt(num_arr.join("")));
localStorage.setItem("deducted", alvar1);
window.location.href = "home.html"
}
function todaysExpenses(){
document.getElementById("spent_points_today").innerHTML = localStorage.deducted ;
document.getElementById("earned_points_today").innerHTML = localStorage.balance;
document.getElementById("balance-remaining").innerHTML = localStorage.balance - localStorage.deducted;
document.getElementById("balance-remaining-month").innerHTML = localStorage.balance - localStorage.deducted;
}
You have to use localStorage.getItem() function 您必须使用localStorage.getItem()函数
or, localStorage["deducted"] 或localStorage [“扣除”]
function todaysExpenses(){
var deducted = parseFloat(localStorage.getItem("deducted"));
var balance = parseFloat(localStorage.getItem("balance"));
document.getElementById("spent_points_today").innerHTML = deducted;
document.getElementById("earned_points_today").innerHTML = balance;
document.getElementById("balance-remaining").innerHTML = (balance - deducted);
document.getElementById("balance-remaining-month").innerHTML = (balance - deducted);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.