これは、ストレージまたはCookieを使用して簡単に実行できます...リスト、値、および必要なすべてのものを、変更されるたびにCookieに保存します。ページの更新時に、Cookieが存在するかどうか、デフォルト値ではなくCookieからリストを取得するかどうかを確認します。
if(typeof(Storage)!=="undefined"){
localStorage.dropdownlist = thelist; // The list being your list of options.
}else{
//Storage not supported, use cookie logic instead.
}
次に、ページの初期化ロジックに従って、次のようなチェックを追加します。
if(typeof(Storage)!=="undefined" && typeof(localStorage.dropdownlist)!=="undefined"){
populateDropDown(localStorage.dropdownlist); // The function being the same as when jQuery calls it.
}else{
//Storage not supported, use cookie logic instead.
}
localStorageオブジェクトは、有効期限なしでデータを保存します。ブラウザを閉じてもデータは削除されず、翌日、翌週、または翌年に利用可能になります。代わりにsessionStorageの使用を検討することをお勧めします。sessionStorageオブジェクトは、1つのセッションのデータのみを格納することを除いて、localStorageオブジェクトと同じです。ユーザーがブラウザウィンドウを閉じると、データは削除されます。