$(data).parent().parent().children().eq(0)取值讲解

<tbody id="content-tbody">
  <tr> 
    <th style="height: 60px">' + item.id + '</th>
    <th style="height: 60px">' + item.sort + '</th>
    <th style="height: 60px">' + item.title + '</th>
    <th style="height: 60px">' + item.type + '</th>
    <th style="height: 60px">' + item.title + '</th>
    <th style="height: 60px">' + item.time + '</th>
    <th style="height: 60px">
   <button class="btn" οnclick="newsUpd(this)" style="width: 36%;height: 40px">编辑     </button>
   <button class="btn" οnclick="newsDel(this)" style="width: 36%;height: 40px">删除    </button>
   </th>
 </tr>
</tbody>
function newsUpd(data) {
    var id = $(data).parent().parent().children().eq(0).text();
    var oldSort = $(data).parent().parent().children().eq(1).text();
    var oldTitle = $(data).parent().parent().children().eq(2).text();
    var oldType = $(data).parent().parent().children().eq(3).text();
    var oldContent = $(data).parent().parent().children().eq(4).text();
}

注意:

     $(data).parent()是tr

     $(data).parent().parent()是tbody

    $(data).parent().parent().children()是所有tbody下的子元素id、oldSort、oldTitle、oldType、 oldContent

  $(data).parent().parent().children().eq(0)是取的eq(index)index第0个位置的子元素id

需要注意:

在ajax方法里写$(this)指向的是最近调用它的jquery对象,所以这里的$(this)指的是ajax对象,
而不是$(".enter_caozuo").find(".gd"),要想解决这个问题
就需考虑增加一个中间变量传递这个对象
在ajax外面弄个变量var mythis = $(this),然后在里面用就行了
 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值