다음과 같은 문제가 있습니다. jquery mobile을 사용하여 webapp을 작성하고 있습니다. webapp의 시작 페이지 (index.html)에서 이벤트 목록을 표시하고 있습니다. 사용자가 이벤트를 클릭하면 (eventsDetail.html)로드됩니다. 이 페이지에서 사용자는 'joinContest 버튼 클릭'을 통해 컨테스트에 참가할 수 있습니다.버튼을 클릭 할 때마다 id localstorage를 저장하는 방법
질문 : 내가 (이 내가 마지막을 클릭 대회의 ID 임) joinContest 버튼을 여러 번 클릭하고 다시 index.html을로 이동하고 하나의 ID 만 저장 한 .btn-showContests 버튼을 클릭 내가 클릭 한 컨테스트의 모든 ID를 저장하려면 어떻게해야합니까? 이렇게하면 index.html로 돌아가서 .btn-showContests를 클릭하면 클릭 한 모든 ID가 표시됩니다.
파일 : eventlist.js
참고 : 나 버튼 .btn-showContests을 클릭 할 때이 기능을 실행
$('.btn-joinContest').live('click', function(e){
if (Modernizr.localstorage) {
var id = getUrlVars()["id"];
localStorage.setItem("contestId", id);
} else {
console.log('browser doesnt support localstorage')
}
});
파일 eventdetails.js.
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);
}
이 작동하지만 어떻게 배열로 밀어 수 있습니까? – pum
배열을 문자열로 지정할 수 있습니다 ... http://stackoverflow.com/questions/3357553/how-to-store-an-array-in-localstorage –
정말 고맙습니다. – pum