gpt4 book ai didi

javascript - localStorage,选择菜单中的选项数据在更改页面时消失

转载 作者:行者123 更新时间:2023-12-03 09:54:29 25 4
gpt4 key购买 nike

我有这段代码,将输入的电话号码写入选择菜单的定义选项中,问题是当我返回或退出应用程序时,数据被删除并且列表为空。我不知道为什么以及如何解决这个问题...

    var flag_beneficiary_account_number=false;
var beneficiary_account_number;
if ( $('#beneficiary_number').val().length > 2 ) {
beneficiary_account_number=$('#beneficiary_number').val();
flag_beneficiary_account_number=true;
} else {
beneficiary_account_number = $('#Beneficiary_number_select').find(":selected").html();
flag_beneficiary_account_number=false;
}

if(flag_beneficiary_account_number){

if(localStorage.getItem("Beneficiary_number_select1")!=beneficiary_account_number &&
localStorage.getItem("Beneficiary_number_select2")!=beneficiary_account_number &&
localStorage.getItem("Beneficiary_number_select3")!=beneficiary_account_number){

var select_counter = parseInt(localStorage.getItem("select-counter"));
var select_option = select_counter%3;
select_counter = select_counter+1;
localStorage.setItem("select-counter",select_counter);

switch (select_option){
case 0:
localStorage.setItem("Beneficiary_number_select1",beneficiary_account_number);
$('#Beneficiary_number_select1').val(beneficiary_account_number);
$('#Beneficiary_number_select1').html(beneficiary_account_number);
break;
case 1:
localStorage.setItem("Beneficiary_number_select2",beneficiary_account_number);
$('#Beneficiary_number_select2').val(beneficiary_account_number);
$('#Beneficiary_number_select2').html(beneficiary_account_number);
break;
case 2:
localStorage.setItem("Beneficiary_number_select3",beneficiary_account_number);
$('#Beneficiary_number_select3').val(beneficiary_account_number);
$('#Beneficiary_number_select3').html(beneficiary_account_number);
break;

default:
break;


}
}
}

最佳答案

当您最终添加 cordova 标记时,我正在编辑您的问题。事情变得很清楚,所以你需要记住,在 Cordova 中,要让 localStorage 工作,请以这种方式使用它

   // To store
window.localStorage.setItem("Beneficiary_number_select2", beneficiary_account_number);

//and to access the value, use
window.localStorage.localStorage
.getItem("Beneficiary_number_select2");

而是 localStorage.getItem("Beneficiary_number_select2")

关于javascript - localStorage,选择菜单中的选项数据在更改页面时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30783083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com