次の問題があります。jquerymobileを使用してWebアプリを構築しています。webapp(index.html)のスタートアップページに、イベントのリストを表示しています。ユーザーがイベントをクリックすると、(eventsDetail.html)が読み込まれます。このページでは、ユーザーは「joinContestボタンをクリック」してコンテストに参加するオプションがあります。
質問: joinContestボタンを複数回クリックしてindex.htmlに戻り、.btn-showContestsボタンをクリックすると、1つのIDのみが保存されました(これは最後にクリックしたコンテストのIDです)。クリックしたコンテスト。index.htmlに戻って.btn-showContestsをクリックすると、クリックしたすべてのIDが取得されますか?
ファイル:eventdetails.js
$('.btn-joinContest').live('click', function(e){
if (Modernizr.localstorage) {
var id = getUrlVars()["id"];
localStorage.setItem("contestId", id);
} else {
console.log('browser doesnt support localstorage')
}
});
ファイル:eventlist.js
注:ボタン.btn-showContestsをクリックすると、この関数が実行されます。
function showContests(){
var contests = localStorage.getItem("contestId");
if(contests == null) {
console.log('Nothing in store');
}
else if (contests.length === 0) {
console.log('Store contains empty value');
}
console.log(contests.length);
}