我在这个本地存储阵列上遇到了困难。希望你能帮帮我。
这是我的代码..
var bank = document.getElementById('name_bank').value;
function AddBank(bank){
var data = JSON.parse(localStorage.bank);
if(!$.inArray( bank, data )){
data[]=bank;
}
localStorage.setItem("bank", JSON.stringify(data));
}
我的错误Uncaught SyntaxError: Unexpected token ]
答案 0 :(得分:0)
请尝试此
<input type="text" id="name_bank" >
<button onclick="AddBank()">
save
</button>
<script>
function AddBank(){
var bank = document.getElementById('name_bank').value;
console.log(bank);
var data = [];
aa = JSON.parse(localStorage.getItem("bank"))
if(aa != null){
data= aa;
}
if(bank != null){
data.push(bank)
}
localStorage.setItem("bank", JSON.stringify(data));
}
</script>
&#13;
答案 1 :(得分:-1)
var bank = document.getElementById('name_bank').value;
function AddBank(bank){
var data = JSON.parse(localStorage.bank);
if(!$.inArray( bank, data )){
data.push(bank);
}
localStorage.setItem("bank", JSON.stringify(data));
}