在所选表格行中显示数据

时间:2017-09-08 08:52:01

标签: jquery

我有使用datepicker和cell的表来显示该日期:

<table class="quartz-table" id="scoreboard_table">   
  <thead>
        <tr class="header_bottom">
          <th>Fullname</th>
          <th>Nickname</th>
          <th class="sorter-false">Feedback</th> 
          <th class="sorter-false">Report</th> 
        </tr>
  </thead>
<?php
    while ($team_row = mysqli_fetch_array($teamByQuarterResult)) {
        $staff_id = $team_row['stf_id']; $username = $team_row['username']; $longname = $team_row['longname'];
        $fb_dt = $team_row['feedback_date'];
?>
    <tbody>
        <tr id='row_<?php echo $staff_id; ?>'>
            <td><?php echo $longname ?></td>
            <td><?php echo $username ?></td>
            <td class='fb_date'>
                <?php if($fb_date != NULL){echo '<i class="fa fa-comments fa-lg" aria-hidden="true"></i><br/>'.$fb_date; } ?>
            </td> 
            <td>  
                <?php if($publish == 1){ ?>
                <input type="hidden" class="datepicker" id="<?php echo $staff_id ?>"><!--<i class="fa fa-calendar" class="datepicker" id="<?php echo $staff_id ?>" aria-hidden="true"></i>-->
                <?php } ?>
            </td>
        </tr>
    </tbody>      
</table> 

允许用户从日历中选择日期的脚本:

<script>
$(function () {
    $( ".datepicker" ).datepicker({
      showOn: "both", 
      buttonText: "<i class='fa fa-calendar fa-2x'></i>",
        onSelect: function(dateText, inst) {
            var ID = $(this).attr('id');
            var fb_date_cell = $(this).closest('tr').attr('id');
            var date = $(this).val();
            $(fb_date_cell + ".fb_date").html(date);
        }      
    });
});
</script>

然后我想在fb_date表格单元格中显示所选日期。但我试过的东西并没有向细胞显示任何东西。如果我只尝试$(".fb_date").html(date); 它将填充表格中的每一行。我只需要选择一行。我该怎么办?

1 个答案:

答案 0 :(得分:1)

尝试替换此行:

var fb_date_cell = $(this).closest('tr').attr('id');

使用以下代码:

var fb_date_cell = $(this).parents('#row_'+ID).find('.fb_date');

另外你应该改变这一行:

$(fb_date_cell).html(date);