简体   繁体   中英

Expandable table when row is clicked, except for last cell

I have a dynamically generated table that takes attendance for students. The rows will expand with additional information about the student, if any part of the row is clicked. My problem is that if the attendance button (red x) is clicked, then the row expands, but the attendance is marked just fine.

出勤表

I found a way to disable the last column (by giving all cells on the last column the same name and using some jquery to make it unclickable), but when doing that the buttons got disabled too.

Javascript/jQuery

$(function () {
    //This is the line I used to disable the last column, but is affecting the buttons
    $('td[name="attend"]').click(function () {
        return false;
    });

    //the rest of the code is used for expanding each row
    $("td[colspan=7]").find("p").hide();
    $("table").click(function (event) {
        event.stopPropagation();
        var $target = $(event.target);
        if ($target.closest("td").attr("colspan") > 1) {
            $target.slideUp();
        } else {
            $target.closest("tr").next().find("p").slideToggle();
        }
    });
});

I have named all the cells in the last column "attend". Any help is much appreciated!

Upon Request, here is the code for each button. Each button is it's own form that is inside the last cell of every row. php

 echo "<td style=\"min-width:75px;\" name=\"attend\">";
    echo "<form method=\"POST\" onSubmit=\"return new_user(this);\" >";
    echo "<input type=\"hidden\" value=\"" . $row2['status'] . "\" name=\"astatus\" />";
    echo "<input type=\"hidden\" value=\"" . $row2['cancel_key'] . "\" name=\"mark_attend\" />";
    echo "<input type=\"image\" src=\"$image\" name=\"pic\" />";
    echo "</form>";
    echo "</td>";

Examine the target tag name like so:

 alert($target.prop('tagName'));

It will be "TD" (or SPAN, or whatever is in the cell), or your button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM