将行内容获取到弹出窗口中

Get row content to a popup window

本文关键字:窗口 获取      更新时间:2023-09-26

当用户单击表行时,我使用此函数弹出一个窗口

<script type="text/javascript">
    $(document).ready(function() {
        $("td.abc").click(function() {
            var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+''n'+''n';
            var r = 'Subject: ' + $(this).find('td:eq(1)').html()+''n'+''n';
            var e = 'Messege: ' + $(this).find('td:eq(2)').html()+''n'+''n';
            var f = 'Developer: ' + $(this).find('td:eq(3)').html()+''n'+''n';
            var w = 'Current Status: ' + $(this).find('td:eq(4)').html()+''n'+''n';
            var q = 'Uploaded Date & Time: ' + $(this).find('td:eq(5)').html()+''n'+''n';
            var o = $("#79").attr("name")+''n'+''n';
            alert(t+r+e+f+w+q+o);
        });
    });
</script>

我的桌子如下

echo "<br> <table border='0' id='example' width='980' align='center'>
<tr>
    <th width='60'>Ticket ID</th>
    <th width='150'>Subject</th>
    <th width='670'>Messege</th>
    <th width='60'>Developer</th>
    <th width='70'>Status</th>
    <th width='105'>Date - Time</th>
</tr>";
while($row = mysql_fetch_array($result)) {
    //echo $row['jobSatus'];
    echo "<tr>";
    echo "<td class='"abc'" width='60'>" . $row['id'] . "</td>";
    echo "<td class='"abc'" width='150'>" . $row['subject'] . "</td>";
    echo "<td class='"abc'" width='670'>" . $row['msg'] . "</td>";
    echo "<td class='"abc'" width='60'>" . $row['developer'] . "</td>";
    echo "<td class='"abc'"width='60'>" . $row['jobstatus'] . "</td>";
    echo "<td class='"abc'" width='105'>" . $row['date_time'] . "</td>";
    echo "<input class='"abc'" type='hidden' name=".$row['image']." id=".$row['id'].">";
    echo "</tr>";
}
echo "</table>";

现在在弹出窗口中,我没有得到任何值。上面写着"未定义"。如果有人能证明我做错了什么,我将不胜感激。

尝试更改此。。。

var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+''n'+''n';

到这个

var t = 'Ticket ID: ' +$(this).closest('td:eq(0)').attr('class');

希望这会有所帮助。。。。

您单击的是表格单元格,而不是表格行

$("td.abc").click(function() {
   ^^

将其更改为查看表

$("#example").on("click", "tr", function () {

$("#example").on("click", "tr:has(td.abc)", function () {

您的HTML标记是无效的,因为输入元素不能是tr.

的子元素

在表行上设置onclick

$("tr.ticker-row").click(function(ev) {
    var $this = $(ev.currentTarget);
    var t = 'Ticket ID: ' + $this.find('td:eq(0)').html()+''n'+''n';
    var r = 'Subject: ' + $this.find('td:eq(1)').html()+''n'+''n';
    var e = 'Messege: ' + $this.find('td:eq(2)').html()+''n'+''n';
    var f = 'Developer: ' + $this.find('td:eq(3)').html()+''n'+''n';
    var w = 'Current Status: ' + $this.find('td:eq(4)').html()+''n'+''n';
    var q = 'Uploaded Date & Time: ' + $this.find('td:eq(5)').html()+''n'+''n';
    var o = $this.find('input').attr('name') + ''n'+''n';
    alert(t+r+e+f+w+q+o);
});

在php上,除了td 之外,不要在tr中插入任何节点

while($row = mysql_fetch_array($result)) {
  //echo $row['jobSatus'];
  echo "<tr class='"ticket-row'" data-row-index='"".$row['id']."'">";
  echo "<td class='"abc'" width='60'>" . $row['id'] . "<input class='"abc'" type='hidden' name=".$row['image']." ></td>";
  echo "<td class='"abc'" width='150'>" . $row['subject'] . "</td>";
  echo "<td class='"abc'" width='670'>" . $row['msg'] . "</td>";
  echo "<td class='"abc'" width='60'>" . $row['developer'] . "</td>";
  echo "<td class='"abc'"width='60'>" . $row['jobstatus'] . "</td>";
  echo "<td class='"abc'" width='105'>" . $row['date_time'] . "</td>";
  echo "</tr>";
  }
echo "</table>";