h5本地存储

//保存数据
        function save(){
            var contact = new Object;
            contact.user_name = document.getElementById("user_name").value;
            contact.mobilephone = document.getElementById("mobilephone").value;
            contact.company = document.getElementById("company").value;
            var str = JSON.stringify(contact);
            localStorage.setItem(contact.mobilephone,str);
            loadAll();
        }
        //将所有存储在localStorage中的对象提取出来,并展现到界面上
        function loadAll(){
            var list = document.getElementById("list");
            if(localStorage.length>0){
                var result = "";
                result += "";
                for(var i=0;i";
                }
                result += "
姓名手机公司
"+contact.mobilephone+""+contact.company+"
"; list.innerHTML = result; }else{ list.innerHTML = "目前数据为空,赶紧开始加入联系人吧"; } }

你可能感兴趣的:(h5本地存储)