x年齢をローカルストレージアイテム 'age'に設定しようとしていますが、わからない理由でこれは機能しません。ローカルストレージがオブジェクトからの値を受け入れない
var x = {
age: 37,
gender: "male",
income: 17000,
};
localStorage.setItem("age") = x.age;
alert(localStorage.getItem('age'));
x年齢をローカルストレージアイテム 'age'に設定しようとしていますが、わからない理由でこれは機能しません。ローカルストレージがオブジェクトからの値を受け入れない
var x = {
age: 37,
gender: "male",
income: 17000,
};
localStorage.setItem("age") = x.age;
alert(localStorage.getItem('age'));
問題はあなたのsyntaxである:
は、ここに私のコードです。この方法で使用する必要があります。
localStorage.setItem("age", x.age)
alert(localStorage.getItem('age'));
アイデアは簡単です。データを名前に格納しています。そして、同じ名前を使用してそれを取得します。
ブラウザで開発者ツールを開きます。コンソールを見てください。あなたの構文が正しい取得後
storage.setItem(keyName, keyValue);
を::
var x = {
age: 37,
gender: "male",
income: 17000,
};
localStorage.setItem("age", x.age);
alert(localStorage.getItem('age'));
Uncaught TypeError: Failed to execute 'setItem' on 'Storage': 2 arguments required, but only 1 present.
は次に述べていたthe manualを見て