for循环中表格的下一个和上一个按钮

时间:2019-07-06 21:26:16

标签: javascript php jquery

当我单击下一步按钮时,显示行..我想在第一页中显示5个表格,然后单击下一步时显示下一个5个表格.. 它在for循环中从数据库获取此表,因此采用相同的类

PHP

$student = "";
foreach ($sql as $sq) {
    if ($student != $sq["Student_ID"]) {
        $student = $sq["Student_ID"];
        echo ' <table class="trs" style="border-bottom: 1px solid #676767;width: 700px;"> <tr><td> <label>
        <input type="submit" class="' . $student . '" style="display: none;"onclick="myFunction()" id="hhh">
            <img  style ="width: 20px"src="images/up-arrow.png"id="file"><br>
        </label></td>';
        echo '<td id="fff">' . $sq["Student_ID"] . '</td></tr>';
    }
    echo ' <tr style="display:none;" class="'. $student . '" >';
    echo '<td class="myDIV">' . $sq["exam_dates"] . '</td>';
    echo '<td class="myDIV">' . $sq["exam_days"] . '</td>';
    echo '<td class="myDIV">' . $sq["Subject_name"] . '</td></tr>';
}
?>
</table>
<a id="next">next</a>
<a id="prev">prev</a>`

和这个js

    $(document).ready(function () {
    $(".file1").click(function () {
        $(".import").show();
    });

    $("*#hhh").click(function () {
        console.log($(this).attr('class'));
        var className = $(this).attr('class');
        $("tr."+className).slideToggle("slow");
    });
});
   $(document).ready(function () {
   $(".trs tr").each(function(e) {
          if (e != 0)
              $(this).hide();
       });
       $("#next").click(function(){
          if ($(".trs tr:visible").next().length != 0)
              $(".trs tr:visible").next().show().prev().hide();
           else {
            $(".trs tr:visible").hide();
            $(".trs tr:first").show();
        }
        return false;
    });

    $("#prev").click(function(){
        if ($(".trs tr:visible").prev().length != 0)
            $(".trs tr:visible").prev().show().next().hide();
        else {
            $(".trs tr:visible").hide();
            $(".trs tr:last").show();
        }
        return false;
    });
});

每个表的类别应不同

0 个答案:

没有答案
相关问题