在IE11中使用本地存储

时间:2014-02-13 22:43:45

标签: javascript internet-explorer local-storage

以下代码在Chrome中运行良好。但是在IE11中,开发者工具给了我这个:

Unable to get property 'clickcount' of undefined or null reference.

以下是代码:

function clickCounter() {
    if(typeof(Storage)!=="undefined") {
        if (localStorage.clickcount) {
            localStorage.clickcount=Number(localStorage.clickcount)+1;
        }
        else  {
            localStorage.clickcount=1;
        }
        document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s).";
    }
    else {
        document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
    }
}

它出自HTML5 Web Storage上的W3schools网页。

怎么办?

0 个答案:

没有答案