如果在jquery中单击该行中的复选框,如何获取行的值

Kat*_*amy 2 ajax checkbox jquery

如果选中同一行复选框,我想获得整行的值.例如

 <table id="tbl" border="1">
    <tr><input type="checkbox" id="selectall"/>
        <td>
        <input type="checkbox"/></td>
 <td>2</td>
<td>3</td>
<td>4</td>
    </tr>
    <tr><td><input type="checkbox"/></td>
 <td>2</td>
<td>3</td>
<td>4</td>
    </tr>
    <tr><td><input type="checkbox"/></td>
 <td>2</td>
<td>3</td>
<td>5</td>
    </tr>
</table>
<input type="button" value="save"/>

$('#selectall').click(function(event) {
          if(this.checked) {
              // Iterate each checkbox
              $(':checkbox').each(function() {
                  this.checked = true;
              });
          }
          else {
            $(':checkbox').each(function() {
                  this.checked = false;
              });
          }

        });

$("#save").click(function(){
   /If all selected value has to pass through ajax one by one row/
});
Run Code Online (Sandbox Code Playgroud)

如果我按下保存按钮,我必须选择所有要检查的行值.请参考这个小提琴.请帮我 .提前致谢

Aru*_*hny 5

尝试

$('#selectall').click(function(event) {
  $(':checkbox').prop('checked', this.checked);
});

$("#save").click(function() {
  //reset the logger
  $('#log').empty();

  //get all the checked checboxex
  $('#tbl input:checkbox:checked').each(function() {
    //for each checked checkbox, iterate through its parent's siblings
    var array = $(this).parent().siblings().map(function() {
      return $(this).text().trim();
    }).get();
    //to print the value of array
    $('#log').append(JSON.stringify(array))
  })
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" id="selectall" />
<table id="tbl" border="1">
  <tr>
    <td>
      <input type="checkbox" />
    </td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" />
    </td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" />
    </td>
    <td>2</td>
    <td>3</td>
    <td>5</td>
  </tr>
</table>
<input type="button" id="save" value="save" />
<div id="log"></div>
Run Code Online (Sandbox Code Playgroud)