我正在使用以下代码来测试HTML 5的会话存储空间。它在所有除IE以外的浏览器中工作正常。安装了IE浏览器的版本是10会话存储在IE中不工作
代码:
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter()
{
if(typeof(Storage)!=="undefined")
{
if (sessionStorage.clickcount)
{
sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
}
else
{
sessionStorage.clickcount=1;
}
document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter is reset.</p>
</body>
</html>
可能是什么问题呢?
它是一个计数器,每增加一次e用户点击“点击我”按钮 – 2013-04-25 11:00:21
它显示脚本错误,因为在if(sessionStorage.clickcount)条件中的未定义引用只在IE中,就像你说的 – Arun 2013-04-25 11:06:19
是的,即使在会话存储中设置它后它不工作。 – 2013-04-25 11:14:32