dtt5830659 2015-08-03 05:21
浏览 13

单击按钮时仅显示$(this)表数据行

I am working on a drop down option feature within a table that loads its data from a mysql database. When a user clicks a button that's within a row it displays table data that was previously hidden. It should only display the data in the row below it but instead it applies this to all rows in the table with class $(.options). The goal is to only apply this to the row under the row that contains .button. This is what I have so far:

CSS:

.options
{
display:none;   
}

MySql Table PHP):

while($sound=mysql_fetch_assoc($records)){
    echo "<tbody>";
    echo "<tr>";
    echo "<td width='40' class='player'>&nbsp;&nbsp;<a href='beats/".$sound['downloadlink']."' class='sm2_button'>Play/</a></td>";
    echo '<td width="250" class="name">'.$sound['name'].'&nbsp;&nbsp;&nbsp;<span class="red date">'.$sound['date'].'</span></td>';
    echo "<td width='88' class='bpm'>".$sound['bpm']." B.P.M.</td>";
    echo "<td width='72' class='length'>".$sound['length']."</td>";
    echo "<td width='275' class='keywords'>".$sound['keywords']."</td>";
    echo "<td width='96' class='buy'><img class='button' src='99cents.png'/></td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td  height='100' class='options' colspan='1'></td>";
    echo "<td class='options' colspan='1'>mp3</td>";
    echo "<td class='options' colspan='2'>wav</td>";
    echo "<td class='options' colspan='2'>tracked out</td>";
    echo "</tr>";
    echo "</tbody>";

Jquery Function:

    $(".button").on('click', function(){
        $('.options').css('display', function(i,v){return v=='none' ? 'inline' : 'none' });
    });
  • 写回答

3条回答 默认 最新

  • donglv7097 2015-08-03 05:30
    关注

    You can use such code in your jQuery function:

    $(".button").on('click', function(){
        // use $(this) to get the element that was clicked. In this case it will be img element
        $(this)
           // find a parent of type tr, that is a row
           .parents('tr')
           // find the next row
           .next('tr')
           // manipulate the item
           .css('display', function(i,v){return v=='none' ? 'inline' : 'none' });
    });
    

    Or since you are doing only show / hide manipulation, instead of your .css() function you can use toggle() function

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错