Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Jquery从最后一个单元格获取Td单元格_Javascript_Jquery_Html - Fatal编程技术网

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();