如何使用jQuery一次显示/隐藏一个动态元素(div) [英] How to show/hide one dynamic element (div) at a time with jQuery

查看:195
本文介绍了如何使用jQuery一次显示/隐藏一个动态元素(div)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试jQuery,并且使用的是我在此处找到的基本教程: http://papermashup.com/simple-jquery-showhide-div/#

This is my first attempt at jQuery and I'm using a basic tutorial I found here: http://papermashup.com/simple-jquery-showhide-div/#

这是我当前的代码以及jQuery的工作方式: http://jsfiddle.net/mZQsu/

This is my current code and how the jQuery works: http://jsfiddle.net/mZQsu/

如您所见,当您单击"+/-"时,它将打开所有4个表/DIV.

As you can see, when you click the '+/-' it opens all 4 of the tables/DIVs.

如何修改此代码以根据原始表仅打开相关的辅助表/div?

How can I modify this code to open just the relevant secondary table/div according to the original table?

(请注意,辅助表是根据PHP和SQL数据动态生成的)

(Please note the secondary tables are generated dynamically from PHP and SQL data)

谢谢.

PS我所有的代码都在这里 http://jsfiddle.net/mZQsu/而不是将其阻塞问题页面:)

P.S all my code is here http://jsfiddle.net/mZQsu/ instead of clogging up this question page :)

推荐答案

DEMO小提琴

$('.toggler').click(function() {   // had to differentiate the main togglers with a new class
    var ind = $(this).parents('tr').index()-1;    // could change
    $(".slidingDiv").eq(ind).slideToggle();
});

$('.show_hide').click(function() {   // this are the 'togglers' inside the big menus
    $(this).parents(".slidingDiv").slideToggle();
});

这篇关于如何使用jQuery一次显示/隐藏一个动态元素(div)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆