English 中文(简体)
如何在酒类时展示/展示一个动态因素(div)
原标题:How to show/hide one dynamic element (div) at a time with jQuery
  • 时间:2012-01-13 00:11:52
  •  标签:
  • php
  • jquery

这是我第一次尝试利用我在这里发现的一个基本理论:

这是我目前的法典,也是“j Query”的工作方式:。 http://jsfiddle.net/mZQsu/

如你所知,当你点击+时,它打开了所有4个表/DIV。

我如何根据原来的表格修改这一法典,只开相关的二读/四?

(请注意,二级表是用购买力平价和数据动态生成的。)

感谢。

P.S. 我的所有法典都载于。 http://jsfiddle.net/mZQsu/ a. 不是掩盖问题网页:

最佳回答

DEMO fiddle

$( .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();
});
问题回答

最好的解决办法是,让你们的四分五裂 s。 E.g.

<div class="slidingDiv" id="ip_127_0_0_1">

并且随后修改相应的联系,以便做到这一点。

$("#ip_127_0_0_1").slideToggle();

so just the associated div gets expanded.

见我更新的dle:。 http://jsfiddle.net/mZQsu/1/

You can use the index of the row, and toggle only the matching row of the other table using jQuery index and eq

See the relivant docs here:

这一工作应当:

$( .show_hide ).click(function() {
    $(this).parents(".slidingDiv").slideToggle();
});

自提单以来 离异等级是淋浴链条的直接母子,我本可以使用“父母”而不是“父母”。 后者提供了更大的灵活性,因为它渗透到所有寻找这一类别的祖先。

Here is a modified code - http://jsfiddle.net/mZQsu/3/

I have added show-hide1, show-hide2, show-hide3, show-hide4. And clicking on it opens respectively slidingDiv1, slidingDiv2, slidingDiv3, slidingDiv4.

When you are binding to an event: You can always grab that event target and reference it.

$( .show_hide ).click(function(e) {
    $(e.target).parent("div.slidingDiv").slideToggle();
});

父母(......)是一个良好的开端,但也可能起作用。 尽管如此,这是解决这一问题的最好办法。

顺便提一下,如果你想要做相反的事情,你会使用......而不是(即目标),除你点击外,所有其他要素都将被称作。

由于您的html是PHP的产物,因此,列入+-链接和碎块独一无二的识别资料不应成为一个问题,例如:

a href="#" class="show_hide" id="show_hide2"

And div class="slidingDiv" id="slidingDiv2"

Then in your click function you get the index of the div that you want to open:


    $(.show_hide).click(function(){
    var $str = $(this).attr( id );
    var $index = $str.charAt( $str.length-1 );
    });

Now you can use index to open the div:


    var divName = "#slidingDiv" + $index;
    $(divName).slideToggle();





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签