我已經儘可能多地閱讀文章,並且除了最後一部分之外,還有大部分工作。我試圖從存儲在localStorage中的日曆中獲取一組事件,然後需要能夠通過按鈕「Saved Events」檢索它們。現在按鈕只檢索一個事件,我需要獲取存儲中的所有事件。我也做了一個小提琴:JSFiddle。LocalStorage Challenge
任何幫助或意見,將不勝感激,這裏是代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style>
.eventer {
background-color:#9CB2B7;
padding: 15px; width: 150px;
height: auto; margin:0; color: #fff;
letter-spacing:0.7px;
}
.selctor {
background-color: #A0AABA;
width: 180px;
}
a {
display: block;
text-decoration: none;
color: #fff;
letter-spacing: 0.7px;
text-align: center;
font-weight: normal;
padding: 5px;
}
#result{ height:200px; outline:dotted 2px red; padding-bottom:150px; }
</style>
</head>
<body>
<div>
<div class="eventer" rel="0"><strong>Event 1 Saturday</strong><br />
yakedi yak</div>
<p class="selctor" rel="0"><a href="#">Add to Schedule</a></p>
</div>
<br /><br />
<div>
<div class="eventer" rel="1"><strong>Event 1 Saturday</strong><br />
more yakedi yak</div>
<p class="selctor" rel="1"><a href="#">Add to Schedule</a></p>
</div>
<br /><br />
<div>
<div class="eventer" rel="2"><strong>Event 3 Sunday</strong>
<p>new yakedi yak</p></div>
<p class="selctor" rel="2"><a href="#">Add to Schedule</a></p>
</div>
<br /><br />
<div>
<div class="eventer" rel="3"><strong>Event 4 Sunday</strong>
<p>blah blah dooodah</p></div>
<p class="selctor" rel="3"><a href="#">Add to Schedule</a></p>
</div>
<br />
<input type="submit" id="buttn" value="Saved Events"><br /><br />
<div>Selected Events are:<br />
<div id="result">
</div>
</div>
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".selctor").click(function() {
var i=$(this).attr("rel");
console.log(i);
var eventsArray=document.getElementsByClassName("eventer");
eventSelctd=(eventsArray[i]).outerHTML;
console.log("selected event is" + " " + eventSelctd);
if (typeof(Storage) != "undefined") {
localStorage.setItem("schedule "+ i, eventSelctd);
}
else {
document.getElementById("#result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
});
$("#buttn").click(function() {
var storaged = localStorage.length;
for(var i=0; i<storaged; i++)
{
console.log("Your stored events are " + localStorage[i]);
var key = localStorage.key(i);
var value = localStorage[key];
$("#result").html(key + value);
//$("#result").html(localStorage[i]);
}
//console.log("stored schedule is " + allEventers);
});
});
</script>
</body>
</html>
你說你做了小提琴? ...我們有可能看到這個機會嗎? – swatkins 2014-12-05 22:07:24
嗨羅伯特,我以爲我做了一個鏈接,它必須剝去html,這裏是:謝謝 – roob 2014-12-05 22:09:11