简体   繁体   English

单击行时的可扩展表,最后一个单元格除外

[英]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. 我的问题是,如果单击了考勤按钮(红色x),则该行会扩大,但是考勤被标记为正常。

出勤表

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. 我找到了一种禁用最后一列的方法(通过为最后一列的所有单元格提供相同的名称,并使用一些jquery使其不可单击),但是这样做时按钮也被禁用了。

Javascript/jQuery 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 的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. 它将是“ TD”(或SPAN,或单元格中的任何内容)或您的按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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