同一页面上多个Jquery滑动面板
我们有一个 asp.NET 页面,它以编程方式将数据添加为无序列表中的新列表项。
我想使用一些 jquery 来显示每个列表项的额外详细信息的滑动面板,但我使用的代码仅显示系列中的第一篇(我猜是因为它们被称为同一件事)..如何添加一些条件来选择正确的条件?
这是代码:
$(document).ready(function(){ $(".btn-slide").click(function(){ $(this).slideToggle("slow"); $(this).toggleClass("active"); return false; }); }); #panel { background: #754c24; height: 200px; display: none; } .slide { margin: 0; padding: 0; border-top: solid 4px #422410; background: #000 no-repeat center top; } .btn-slide { background: url(images/white-arrow.gif) no-repeat right -50px; text-align: center; width: 144px; height: 31px; padding: 10px 10px 0 0; margin: 0 auto; display: block; font: bold 120%/100% Arial, Helvetica, sans-serif; color: #fff; text-decoration: none; } .active { background-position: right 12px; }
<代码>
<% foreach( var registration in ViewModel ) { %>
<li>
Event: <%= registration.Event.Name %>
Date: <%= registration.Event.Date.ToLongDateString() %>
<div id="panel">
<% if ( registration.HasResult ) { %>
Your result for this event:
Place: <%= registration.Result.Place %>
Time: <%= registration.Result.Time %>
Average Pace: <%= registration.Result.AveragePace %>
<% } else { %>
No results have been posted for this event.
<% } %>
</div>
<p class="slide"><a href="#" class="btn-slide">Slide Panel</a></p>
</li>
<% } %>
</ul>
> <代码>
We have an asp.NET page which is programmaticaly adding data as new list items in an unordered list..
I want to use some jquery to show a sliding panel of extra detail for each list item but the code I'm using only shows the first in the series (as I'm guessing because they are called the same thing) .. How do I add some conditions to choose the correct one?
Here is the code:
$(document).ready(function(){ $(".btn-slide").click(function(){ $(this).slideToggle("slow"); $(this).toggleClass("active"); return false; }); }); #panel { background: #754c24; height: 200px; display: none; } .slide { margin: 0; padding: 0; border-top: solid 4px #422410; background: #000 no-repeat center top; } .btn-slide { background: url(images/white-arrow.gif) no-repeat right -50px; text-align: center; width: 144px; height: 31px; padding: 10px 10px 0 0; margin: 0 auto; display: block; font: bold 120%/100% Arial, Helvetica, sans-serif; color: #fff; text-decoration: none; } .active { background-position: right 12px; }
<% foreach( var registration in ViewModel ) { %>
<li>
Event: <%= registration.Event.Name %>
Date: <%= registration.Event.Date.ToLongDateString() %>
<div id="panel">
<% if ( registration.HasResult ) { %>
Your result for this event:
Place: <%= registration.Result.Place %>
Time: <%= registration.Result.Time %>
Average Pace: <%= registration.Result.AveragePace %>
<% } else { %>
No results have been posted for this event.
<% } %>
</div>
<p class="slide"><a href="#" class="btn-slide">Slide Panel</a></p>
</li>
<% } %>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改 div 以使用面板的类而不是 id。
然后像这样切换幻灯片:
这将获取带有类面板的 div,该面板存在于锚点父级的父级中。
Change the div to use class of panel instead of id.
Then toggle the slide like this:
This will get the div with class panel that exists in the parent of the anchor's parent.
您可以使用每个方法来做到这一点...
You can do that with the each method...
HTML 元素的 ID 必须是唯一的,因此您的循环会生成无效的 HTML。尝试为您的 DIV 分配一个类而不是 ID。
已更新:您的 JavaScript 看起来也不正确:
IDs of HTML elements must be unique so your loop is producing invalid HTML. Try assigning a class instead of an ID to your DIV.
Updated: Also your javascript doesn't look right: