简体   繁体   English

在这种情况下如何获取选定的表 tr 行

[英]How to fetch the selected table tr row in this case

I am having a table as shown below我有一张如下所示的表格

On click of a button how to fecth the selected tr mobile number单击一个按钮如何获取选定的 tr 手机号码

<table class="table table-striped table-bordered table-hover table-full-width dataTable" id="sample_2" aria-describedby="sample_2_info">
   <tbody role="alert" aria-live="polite" aria-relevant="all">
      <tr class="vendorslist odd">
         <td class=" "><label class="radio"><input type="radio" onclick="UpdateButtonTest(this);" id="5300085118-90304910251387" name="optionsRadios1" value="option1"></label></td>
         <td class=" sorting_1"> VENDOR</td>
         <td class=" ">5300085118</td>
         <td class=" ">544444444</td>
         <td class=" ">Restaurant</td>
         <td class=" ">Restaurants</td>
         <td class=" ">wer@gmail.com</td>
         <td class=" "><span id="span-5300085118-90304910251387" class="label label-success">Active</span></td>
      </tr>
      <tr class="vendorslist odd">
         <td class=" "><label class="radio"><input type="radio" onclick="UpdateButtonTest(this);" id="5300085118-90304910251387" name="optionsRadios1" value="option1"></label></td>
         <td class=" sorting_1"> VENDOR</td>
         <td class=" ">5300085118</td>
         <td class=" ">900000000</td>
         <td class=" ">Restaurant</td>
         <td class=" ">Restaurants</td>
         <td class=" ">serr@gmail.com</td>
         <td class=" "><span id="span-5300085118-90304910251387" class="label label-success">Active</span></td>
      </tr>
   </tbody>
</table>
<button id="btnSave">Save Click</button>

This is my fiddle这是我的小提琴

https://jsfiddle.net/atg5m6ym/4123/ https://jsfiddle.net/atg5m6ym/4123/

Could you please let me know how to fecth the mobile number of the selected table tr你能告诉我如何获取所选表tr的手机号码吗?

Means for first i need the value 544444444 and in case of second i need 900000000意味着首先我需要值 544444444 并且在第二个的情况下我需要 900000000

it would be easier with a class on the mobile td , but you could do:-在移动td上上课会更容易,但您可以这样做:-

 $(document).on('click', '#btnSave', function() { var mobile = $('table :checked').closest('tr').find('td:eq(3)').text(); alert(mobile); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table class="table table-striped table-bordered table-hover table-full-width dataTable" id="sample_2" aria-describedby="sample_2_info"> <tbody role="alert" aria-live="polite" aria-relevant="all"> <tr class="vendorslist odd"> <td class=" "> <label class="radio"> <input type="radio" onclick="UpdateButtonTest(this);" id="5300085118-90304910251387" name="optionsRadios1" value="option1"> </label> </td> <td class=" sorting_1">VENDOR</td> <td class=" ">12222</td> <td class=" ">544444444</td> <td class=" ">Restaurant</td> <td class=" ">Restaurants</td> <td class=" ">wer@gmail.com</td> <td class=" "><span id="span-5300085118-90304910251387" class="label label-success">Active</span> </td> </tr> <tr class="vendorslist odd"> <td class=" "> <label class="radio"> <input type="radio" onclick="UpdateButtonTest(this);" id="5300085118-90304910251387" name="optionsRadios1" value="option1"> </label> </td> <td class=" sorting_1">VENDOR</td> <td class=" ">12233</td> <td class=" ">900000000</td> <td class=" ">Restaurant</td> <td class=" ">Restaurants</td> <td class=" ">serr@gmail.com</td> <td class=" "><span id="span-5300085118-90304910251387" class="label label-success">Active</span> </td> </tr> </tbody> </table> <button id="btnSave">Save Click</button>

Through jQuery parents()通过jQuery parents()

$(document).on('click', '#btnSave', function() {

    alert($('.vendorslist input:checked').parents("tr").find('td').eq(3).text());

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM