Javascript 使用Jquery从最后一个单元格获取Td单元格
我有一张这样的桌子:Javascript 使用Jquery从最后一个单元格获取Td单元格,javascript,jquery,html,Javascript,Jquery,Html,我有一张这样的桌子: <table class="table table-striped table-bordered table-hover"> <thead> <tr> <th class="center" style="width: 30%">Name</th>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="center" style="width: 30%">Name</th>
<th class="hidden-480 center" style="width: 40%">URI</th>
<th class="hidden-phone center" style="width: 30%">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name">
Admin_Agency
</td>
<td class="uri">
/admin/agency
</td>
<td>
<a href="#modalEdit">
<i class="icon-pencil"></i>
<span>Edit</span>
</a>
<a href="#modalDelete">
<i class="icon-trash"></i>
<span>Delete</span>
</a>
</td>
</tr>
<tr>
<td class="name">
System_Log
</td>
<td class="uri">
/admin/syslog
</td>
<td>
<a href="#modalEdit">
<i class="icon-pencil"></i>
<span>Edit</span>
</a>
<a href="#modalDelete">
<i class="icon-trash"></i>
<span>Delete</span>
</a>
</td>
</tr>
</tbody>
</table>
代码没有运行
有什么建议吗?
谢谢您必须使用
closest()
获取其父级tr,然后使用find()
通过类选择器获取td,并使用text()
获取td开始标记和结束标记之间的文本
像这样:
var name = $(this).closest("tr").find(".name").text();
var uri = $(this).closest("tr").find(".uri").text();
什么是%#!$?你的代码应该可以工作。。。!但它不起作用:(你的代码对我来说很好。
var name = $(this).closest("tr").find(".name").text();
var uri = $(this).closest("tr").find(".uri").text();