sessionStorage isn't working as expected

前端 未结 2 1399
有刺的猬
有刺的猬 2021-01-23 07:11

Here is my code:

    sessionStorage.loggedIn = true;

    if (sessionStorage.loggedIn) {
        alert(\'true\');
    }
    else {
        alert(\'false\');
            


        
2条回答
  •  星月不相逢
    2021-01-23 07:57

    Keys and Values in a WebStorage object (sessionStorage) must be strings. If they are not strings they "should" be converted to strings in the browser's implementation when you assign to sessionStorage. If you evaluate against "true" or convert to boolean it will work fine.

    https://code.google.com/p/sessionstorage/

    http://www.w3schools.com/html/html5_webstorage.asp

提交回复
热议问题