문제

I have a ID (1) of a record in the database and each time when I click the "NEXT" button, I wish to increment the ID into 2 and retrieve the next data. I store the ID into the sessionStorage.ID and later when I retrieve it and

sessionStorage.ID =sessionStorage.ID +1

The sessionStorage should be equal to 2 but it display as "11". How can I resolve this?

도움이 되었습니까?

해결책

Try this:

sessionStorage.ID = parseInt(sessionStorage.ID) + 1;

When you store the ID in sessionStorage, it gets saved as a string, so the + sign concatenates the number instead of adding it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top