简体   繁体   English

我想使用 jQuery 获取复选框的值

[英]I want to get the value of checkbox using jQuery

In a table there are multiple rows, what I want is if I click on a particular name of user like "Sam" and "Adem" I want to get the value of checkbox which only relates to that row.在一个表中有多行,我想要的是如果我点击一个特定的用户名,比如“Sam”和“Adem”,我想获得只与该行相关的复选框的值。

<thead>
  <tr>
    <td>Select</td>
    <td>Name</td>
    <td>Username</td>
    <td>Rank</td>
    <td>Address</td>
  </tr>
</thead>
<tbody>
  <tr>
    <td><input type="checkbox" name="" id="" value="1"></td>
    <td>Sam</td>
    <td>Sam001</td>
    <td>Admin</td>
    <td>XYZ</td>
  </tr>
  <tr>
    <td><input type="checkbox" name="" id="" value="2"></td>
    <td>Adem</td>
    <td>Adem002</td>
    <td>Manager</td>
    <td>ZYZ</td>
  </tr>
  <tr></tr>
  <tr></tr>

Attach click event on TD elements.在 TD 元素上附加点击事件。 In the handler find the checkbox using .parent() and .find() methods.在处理程序中使用.parent().find()方法找到复选框。 When you have found the checkbox, get its value using .val() method.找到复选框后,使用.val()方法获取其值。

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

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