我试图弄清楚如何使用键/值对系统将动态创建的列表元素存储在本地存储中,但无法弄清楚...
我有一个栏列表,可以通过单击将其添加到“收藏夹”列表中单个栏页面上的星号,克隆特定列表元素,然后将其附加到收藏夹列表。
我不知道如何使用本地存储来存储这些信息...
这是使用 Jquery 切换类、交换图像然后克隆并附加到 #favorites ul 的 JS
$("document").ready(function() {
$('#club1668Star').toggle(club1668Blue, club1668White)
function club1668Blue(evt) {
$('#club1668Star').toggleClass('club1668Blue').attr("src", "media/images/bluestar40.png");
$("#barlist li[id=club1668List]").toggleClass('club1668Fav');
$("#barlist li[class=club1668Fav]").clone().appendTo("#favourites ul[class=plasticBar]");
}
function club1668White(evt) {
$('#club1668Star.club1668Blue').removeClass('club1668Blue').attr("src", "media/images/whitestar40.png")
$("#barlist li[class=club1668Fav]").toggleClass('club1668Fav');
$("#favourites ul[class=plasticBar] li[id=club1668List]").remove();
}
});
任何帮助将不胜感激...
干杯,
标记
I am trying to figure out how to store dynamically created list elements in local storage with the key/value pair system, but cannot figure it out...
I have a list of bars which can be added to a 'favorites' list by click a star on the individual bar's page and having the particular list element cloned and then appended to the favorites list.
I can't figure out how to store this information using local storage...
This is the JS using Jquery toggling a class, swapping an image and then cloning and appending to the #favorites ul
$("document").ready(function() {
$('#club1668Star').toggle(club1668Blue, club1668White)
function club1668Blue(evt) {
$('#club1668Star').toggleClass('club1668Blue').attr("src", "media/images/bluestar40.png");
$("#barlist li[id=club1668List]").toggleClass('club1668Fav');
$("#barlist li[class=club1668Fav]").clone().appendTo("#favourites ul[class=plasticBar]");
}
function club1668White(evt) {
$('#club1668Star.club1668Blue').removeClass('club1668Blue').attr("src", "media/images/whitestar40.png")
$("#barlist li[class=club1668Fav]").toggleClass('club1668Fav');
$("#favourites ul[class=plasticBar] li[id=club1668List]").remove();
}
});
any help would be greatly appreciated...
cheers,
mark
发布评论
评论(2)
有一种众所周知的方法可以将多个 JS 对象作为单个值传递,它称为 JSON。难道不适合你吗?
There's a well-known way to pass multiple JS objects as a single value, it is called JSON. Can't it suit you?
您可以将多个属性组合成对象,然后将对象存储在 localStorage 中。默认情况下,localStorage 键/值对将值存储为字符串,但是您可以使用在字符串和对象之间进行转换的内容来包装它 - 在 HTML5 localStorage 中存储对象
You can group multiple attributes together into objects, then store the objects in localStorage. By default, the localStorage key/value pairs stores the values as strings, however you can wrap this with something that converts between strings and objects - there are some examples on how to do this at Storing Objects in HTML5 localStorage