如何在与单击功能不同的页面上的 Li 元素上切换类

发布于 2024-09-28 22:41:30 字数 1465 浏览 4 评论 0原文

我正在尝试在我正在开发的这个应用程序中创建一个动态收藏夹列表。我目前的问题是我无法指示事件来切换特定的 li 类名称。我有一个很大的 li 列表以及与它们相关的单独页面。每个页面都有一个标题栏,其中包含多个图像链接、电话号码等。最后一个图像是一颗星星,当用户单击它时我需要将其变成蓝色,并在另一个页面上切换其相应 li 元素的类。我不想为每个元素编写单独的代码,并且我在尝试将每个星形点击与 37 个 li 元素之一关联起来时变得更加沮丧...我使用了 jquery 但无法弄清楚这一点...

包含 li 的 div我需要切换元素,以便将它们克隆到另一个

<div id="barlist">
  <div class="toolbar"><h1>Bar List</h1><a class="button back"Back</a>
     <a class="button flip" Settings</a>
 </div>
 <ul class="edgetoedge">    
   <li class="aleHouse"><a Ale House</a></li>
   <li class="argyle"><a Argyle</a></li>
   <li class="bearlys"><a Bearlys</a></li>
   <li class="bostonPizza"><a>Boston Pizza</a></li>
 </ul>
</div>

带有星形图像的“收藏夹”列表对应页面

<div id="aleHouse">
   <div class="toolbar"><h1>Ale House</h1><a class="button back" >Back</a>    
</div>
<div>
<div class="blackBar">
  <img class="white" img src=".../whitestar40(png)" alt="star">
</div>

$("document").ready(function() {
  $("#barlist li[class=fav]").clone().appendTo("#favorites[class=edgetoedge]");
});

$("document").ready(function() {  
  $(".white").click(function() {   $(???this???).toggleClass(".fav");  })
});

,例如,当单击whitestar40时,我希望它变成蓝色,并克隆啤酒屋li(单击以获取到此页面)并附加到另一页上的我的收藏夹列表

I am attempting to create a dynamic favorites list in this application i'm working on. My problem at the moment is I cannot direct an event to toggle specific li class names. I have a large list of li's and seperate pages associated with them. Each page has a title bar with several image links, phone number, etc. the last image is a star which i need to have turn blue when the user clicks on it as well as toggle the class of its corresponding li element on another page. I don't want to have to write individual code for each element and i am becoming more frustrated trying to correlate each star click with one of 37 li elements... i have used jquery but cannot figure this out...

div containing li elements i need to toggle in order to clone them to another "favorites" list

<div id="barlist">
  <div class="toolbar"><h1>Bar List</h1><a class="button back"Back</a>
     <a class="button flip" Settings</a>
 </div>
 <ul class="edgetoedge">    
   <li class="aleHouse"><a Ale House</a></li>
   <li class="argyle"><a Argyle</a></li>
   <li class="bearlys"><a Bearlys</a></li>
   <li class="bostonPizza"><a>Boston Pizza</a></li>
 </ul>
</div>

corresponding page with star image

<div id="aleHouse">
   <div class="toolbar"><h1>Ale House</h1><a class="button back" >Back</a>    
</div>
<div>
<div class="blackBar">
  <img class="white" img src=".../whitestar40(png)" alt="star">
</div>

$("document").ready(function() {
  $("#barlist li[class=fav]").clone().appendTo("#favorites[class=edgetoedge]");
});

$("document").ready(function() {  
  $(".white").click(function() {   $(???this???).toggleClass(".fav");  })
});

for instance, when the whitestar40 is clicked, i want it to turn blue and also clone the the ale house li (which was clicked to get to this page) and appendTo my favorites list on another page

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

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

发布评论

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

评论(1

伏妖词 2024-10-05 22:41:30

我假设您同时显示这两个页面? ...而不是尝试在请求中存储信息(whitestar40 被点击)。
我首先向whitestar40 添加一些属性来跟踪单击的内容,并在单击发生时对其进行设置。然后你就可以在另一个页面的 html/dom 中获得所需的数据。这有助于或让果汁流动吗?

I'm assuming that you are displaying both these pages at the same time? ...As opposed to trying to store the info(that the whitestar40 was clicked) across the request.
I'd start by adding some attribute to the whitestar40 that keeps track of what li was clicked, and set it when that click happens. Then you have the data you need in the html/dom on the other page. Does that help or get the juices flowing?

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