window.localStorage.setItem 无法在移动设备上工作 phone

window.localStorage.setItem not working on mobile phone

我正在使用 jQuery 移动设备开发 HTML5 移动应用程序。

这是我的代码:

$(document).on("click","#send_mobile_number",function(){

    var mobile = $('#mobile_number').val();
    var user_id = sessionStorage.getItem("user_id");


    $('.ui-loader').show();

    $.ajax({
        url: BASE_URL+'users/send_sms_code.php',
        type: 'POST',
        datatype: 'json',
        data: "user_id="+user_id+"&mobile="+mobile+"&type=1",
        async:false,
        success: function (response) {
            var data = jQuery.parseJSON(response);
            $('.ui-loader').hide();

            if(data.status == 'Fail') {
                $('.very_mob_no_message').html('Sorry some error occurred,try again.');
            }else{                   
                $('#close_mob_popup').trigger('click');

                setTimeout(function()
                {
                    $('.click_mobile_verify').trigger('click');
                }, 500);

                $('#send_mobile_verify_span').hide();
                $('#after_mobile_send_span').show();

                $('#moble_number_div').hide();
                $('#user_code_div').show();

                $('#user_code').val(data.sms_code);

                //alert(window.localStorage.getItem('mobile'));

                //sessionStorage.setItem("mobile",mobile);
                window.localStorage.setItem("mobile",mobile); // IT IS NOT WORKING


                $('.very_mobile_message').html('Enter code which is <br/> sent to your mobile number.');

            }


        },
        error: function (jqXHR, textStatus, errorThrown) {

            //alert(jqXHR.status);
        }
    });  

});

我想使用 window.localStorage.setItem("mobile",mobile); 在会话中存储手机号码。当我在浏览器上 运行 时它可以工作,但是当我 运行t 在手机上 phone 作为 APP 时它停止工作。为什么会这样。我正在检查 android phone.

只需使用localStorage.mobile = "mobile"。就这么简单。 localStorage 是一个全局对象,可以像任何其他对象一样访问和操作。与常规对象的唯一区别是它只能存储字符串。

然后您可以使用 alert( localStorage.mobile ); // will alert "mobile"

检索您的值

所以终于找到了解决方案,我需要在 android 代码上设置 webSettings.setDomStorageEnabled(true); 并且在这个本地存储完美运行之后。