关于使用jQuery如何获取table表格点击行的值

时间:2021-01-26 12:17:01   收藏:0   阅读:0
表格美化
Info Header 1 Info Header 2 Info Header 3 操作
Text 1A Text 1B Text 1C
Text 2A Text 2B Text 2C
Info Header 1 Info Header 2 Info Header 3
Text 1A Text 1B Text 1C
Text 2A Text 2B Text 2C
Text 3A Text 3B Text 3C
Text 4A Text 4B Text 4C
Text 5A Text 5B Text 5C

html代码如下

<table class="m-tb2">
 <tr>
    <th style="width:10px;"><input id="SelectAll" type="checkbox" /></th>
    <th>Info Header 1</th>
    <th>Info Header 2</th>
    <th>Info Header 3</th>
    <th style="width:50px;">操作</th>
 </tr>
 <tr>
    <td><input id="" class="SelectSingle" type="checkbox" value=""/></td>
    <td>Text 1A</td>
    <td>Text 1B</td>
    <td>Text 1C</td>
    <td><input class="Select" id="ButtonSelect" type="button" value="选择" /></td>
 </tr>
 <tr>
    <td><input id="" class="SelectSingle" type="checkbox" value=""/></td>
    <td>Text 2A</td>
    <td>Text 2B</td>
    <td>Text 2C</td>
    <td><input class="Select" id="ButtonSelect" type="button" value="选择" /></td>
 </tr>
</table>

js代码:

$(‘.Select‘).click(function(event) {
    var tr = $(this).closest("tr")
    var colData = tr.find("td:eq(1)").text()
    alert(colData)
});
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!