html5 localStorage 混乱

发布于 2024-10-13 13:11:59 字数 939 浏览 4 评论 0 原文

我试图弄清楚如何使用键/值对系统将动态创建的列表元素存储在本地存储中,但无法弄清楚...

我有一个栏列表,可以通过单击将其添加到“收藏夹”列表中单个栏页面上的星号,克隆特定列表元素,然后将其附加到收藏夹列表。

我不知道如何使用本地存储来存储这些信息...

这是使用 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

獨角戲 2024-10-20 13:12:01

有一种众所周知的方法可以将多个 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?

猫瑾少女 2024-10-20 13:12:01

您可以将多个属性组合成对象,然后将对象存储在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文