0

我有一个滑动开关,可以在第二列的同一个表格单元格中切换一个 div。这很好用。但我也想单击表格第一列的单元格中的某些内容来切换第二列中的相同 div。

我认为这是第一列中的操作需要有所不同的地方:

jQuery(".heading2").click(function(){jQuery(this).next(".content2").slideToggle(500);});

就像是:

jQuery(".heading1").click(function(){jQuery(this).next(".content2" *in next column* ).slideToggle(500);});

HTML是这样的:

   <tr>
    <td valign="top" align="left" width="70">
        <div class="heading1">
            <img id="After Earth" src="http://content6.flixster.com/movie/11/17/10/11171008_mob.jpg" style="border-width:0px;cursor:pointer;" />
        </div>
    </td>

    <td valign="top" align="left">

        <div class="heading2">
            <b class="title1">After Earth</b> <img id="eye771268396" src="images/eye15.png" style="border-width:0px;" class="hidepic" /><br />
            <b>Starring: </b>Will Smith, Jaden Smith, Zoe K..<br />
            <b>Director: </b><br />
        </div>

        <div class="content2">
            <b>Rating: </b>PG-13<br />
            <b>Runtime: </b>100 mins<br />
            <b>Description: </b>A crash landing leaves teenager Kitai Raige (Jaden Smith) and his legendary father Cypher (Will Smith) stranded on Earth, 1,000 years after cataclysmic events forced humanity's escape. With Cypher critically injured, Kitai must embark on a perilous journey to signal for help, facing uncharted terrain, evolved animal species that now rule the planet, and an unstoppable alien creature that escaped during the crash. Father and son must learn to work together and trust one another if they want any chance of returning home. (c) Sony<br />
        </div>

    </td>
</tr>
4

2 回答 2

0

根据我对您的问题的理解,我建议:

jQuery('.heading1, .heading2').click(function(){
    jQuery(this).closest('tr').find('.content2').slideToggle(500);
});

JS 小提琴演示

参考:

于 2013-07-17T06:47:32.573 回答
0

这是小提琴

jQuery(".heading2").click(function () {
    jQuery(this).next(".content2").slideToggle(500);
});
jQuery(".heading1").click(function () {
    jQuery(this).closest('td').next('td').find(".content2").slideToggle(500);
});
于 2013-07-17T06:17:33.877 回答