如何获取刚刚删除的行的文本值-Jquery / Js

时间:2016-02-02 19:38:24

标签: javascript jquery

我点击删除链接会删除表格中的行。

<div class="container">
    <div class="content-box big-box">
        <div class="table-responsive">
            <h2 class="payrollTitle">TITLE</h2>
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Day</th>
                        <th>Prop1</th>
                        <th>Prop2</th>
                        <th>Prop3</th>
                        <th ng-repeat="com in vm.companies">{{com}}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="day in vm.array">
                        <th scope="row">{{day.Date}}</th>
                        <td>{{day.Date}}</td>
                        <td>{{day.prop1}}</td>
                        <td>{{day.prop2}}</td>
                        <td>{{day.prop3}}</td>
                        <td>**HERE IS MY PROBLEM - HOW I CAN TO PUT SALARY UNDER RIGHT COMPANY????**</td>

                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

这是js我试图找到我刚刚删除的行:

<table id="cont">
 <tbody>
   <tr>
    <td>
       <label>account name</label>
    </td>
   </tr>
   <tr>
    <td>
       <label>type</label>
    </td>
   </tr>
   <tr>
     <td><a class=delete href='/url/delete'>Delete</a></td>
   </tr>
  </tbody>
 </table>

任何想法赞赏!! 感谢..

3 个答案:

答案 0 :(得分:2)

我不知道你的意思是什么,如果你的意思是innerHTML,你可以先存储然后删除元素。

A <- matrix(0, nrow = 5, ncol = 5)
A[2, 2] <- 1
A[5, 5] <- 1
A
#      [,1] [,2] [,3] [,4] [,5]
# [1,]    0    0    0    0    0
# [2,]    0    1    0    0    0
# [3,]    0    0    0    0    0
# [4,]    0    0    0    0    0
# [5,]    0    0    0    0    1

spread <- function(x) {
  idx <- do.call(rbind, apply(which(x == 1, arr.ind = TRUE), 1, 
                              function(y) expand.grid(y[1] + 1:-1, y[2] + 1:-1)))
  idx <- idx[!(idx[, 1] %in% c(0, nrow(x) + 1) | idx[, 2] %in% c(0, ncol(x) + 1)), ]
  x[as.matrix(idx)] <- 1
  x
}

spread(A)
#      [,1] [,2] [,3] [,4] [,5]
# [1,]    1    1    1    0    0
# [2,]    1    1    1    0    0
# [3,]    1    1    1    0    0
# [4,]    0    0    0    1    1
# [5,]    0    0    0    1    1

spread(spread(A))
#      [,1] [,2] [,3] [,4] [,5]
# [1,]    1    1    1    1    0
# [2,]    1    1    1    1    0
# [3,]    1    1    1    1    1
# [4,]    1    1    1    1    1
# [5,]    0    0    1    1    1

答案 1 :(得分:1)

您可以先缓存单元格,然后再获取outerHTML

$('.delete').on('click', function(e) {
  var $p = $(this).parent();

  $p.remove();

  //how to get the <tr> that just deleted
  alert("deleted " + $p[0].outerHTML);
});

小提琴here

答案 2 :(得分:1)

这取决于你想要的&#39;价值&#39;队友!

如果您想要表格的id

$(this).closest('table').attr('id');

如果您想要帐号ID或类型,可以轻松完成

$(this).closest('table').find('lable'); 

它应该为你提供一个包含

中的两个元素的数组