【发布时间】:2015-08-12 20:33:03
【问题描述】:
我正在使用以下代码来测试 HTML 5 的会话存储。它在除 IE 之外的所有浏览器中都可以正常工作。安装的IE版本是10。
代码:
<!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>
可能是什么问题?
【问题讨论】:
-
这是一个计数器,每次用户点击“点击我”按钮时都会递增
-
它显示脚本错误由于 if (sessionStorage.clickcount) 条件中未定义的引用,仅在 IE 中,就像你说的那样
-
是的,即使在会话存储中设置后它也无法正常工作。
-
我建议您查看 MSDN 了解更多详细信息 .. w3schools 关于会话存储的示例返回相同的错误。
-
在 MSDN 中提到以“window.sessionStorage”的形式访问它,但这也不起作用。
标签: html session internet-explorer-10 session-storage