/*我将用户输入的数据存入了一个对象再将这个对象转换成了字符串并用localstorage.setItem方法存入了本地数据请问该怎么取用这个字符串内的数据啊*/<script>//获取table元素var tt=document.getElementById("tt");//定义thesrt变量来var thestr;function xianshi(){thestr=localStorage.getItem("thestr");if(thestr){thestr=JSON.parse(thestr);}else{thestr=[];}for(var i=thestr.length-1;i>=0;i--){var row=tt.insertRow();row.insertCell().innerHTML=thestr[i].name;row.insertCell().innerHTML=thestr[i].sex;row.insertCell().innerHTML=thestr[i].number;row.insertCell().innerHTML=thestr[i].age;}}xianshi();function shanchu(){var shanchu2=document.getElementById("shanchu1").value;for(var i=0;i<=tt.rows.length-1;i++){if(tt.rows[i].children[2].innerHTML==shanchu2){tt.deleteRow(i);localStorage.removeItem("thestr","tt.rows[i]");}}}function qinchu(){for(var i=tt.rows.length-1;i>=1;i--){tt.deleteRow(i);}}function tianjia(){var a=document.getElementById("name").value;var b=document.getElementById("number").value;var c=document.getElementById("age").value;var dd=document.getElementsByName("sex");var d=dd[0].checked ? dd[0].value : dd[1].value;var str=new Object();str.name=a;str.sex=d;str.number=b;str.age=c;thestr[thestr.length]=str;localStorage.setItem("thestr",JSON.stringify(thestr));console.log(localStorage);qinchu();xianshi();}</script>
添加回答
举报
0/150
提交
取消