私は次のものを持っていますが、null
保存しようとしていた値ではなく、戻り値を取得し続けています。これが私のコードです:
function mySelectValue() {
// Add an event listener for the value
document.getElementById('mySelectValue').addEventListener('change', function() {
// Get the value of the name field.
var mySelectValue = document.getElementById('mySelectValue').value;
// Save the name in localStorage.
localStorage.setItem('mySelectValue', mySelectValue);
});
}
ただし、値を取得しようnull
とすると、値が保存されていないことを意味すると思います。
基本的に、オプションを選択するとすぐに(まだ送信しないで)、ローカルストレージに保存したいと考えています。また、選択を変更すると値が上書きされるようにします。