<html>
<head>
<title></title>
<style type="text/css">
body
{
font-family: tahoma;
}
h2
{
font-weight: bold;
border-bottom: 2px solid gray;
margin-bottom: 10px;
}
#data
{
border: 1px solid grey;
}
</style>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var prefix = "HTML5LocalStorage-";
$("#save").click(function () {
var key = $("#key").attr('value');
var value = $("#value").attr('value');
localStorage.setItem(prefix + key, value);
RewriteFromStorage();
});
function RewriteFromStorage() {
$("#data").empty();
for (var i = 0; i < localStorage.length; i++)
{
var key = localStorage.key(i);
if (key.indexOf(prefix) == 0) {
var value = localStorage.getItem(key);
var shortkey = key.replace(prefix, "");
$("#data").append(
$("<div class='kvp'>").html(shortkey + "=" + value)
.append($("<input type='button' value='Delete'>")
.attr('key', key)
.click(function () {
localStorage.removeItem($(this).attr('key'));
RewriteFromStorage();
})
)
);
}
}
}
RewriteFromStorage();
</script>
<h2>
LocalStorage Demo</h2>
<div id="data">
</div>
<hr />
<span>Key</span><input type="text" id="key" /><span>Value</span><input type="text"
id="value" />
<input type="button" id="save" value="Save" />
我已经在 localstorage.htm 页面(visual studio 2010)中编写了上面的代码行,但是在按钮单击中没有输出。我犯了什么错误。我是这项技术的新手。