Domanda

I have this table and I have to traverse using Jquery:

<table id="answer">
<thead>
  <tr class="grdheader">
    <td><input type="checkbox" style="border:0px"id="a1chkAll"></td>
    <td>Free Text</td>
    <td>Weighting</td>
  </tr>
</thead>
<tbody>
  <tr id="tdata">
    <td><input type="checkbox" value="440" id="achk" checked="checked"></td>
    <td>ABC</td>
    <td>2</td>
  </tr>
  <tr id="tdata">
    <td><input type="checkbox" value="440" id="achk" checked="checked"></td>
    <td>PQR</td>
    <td>4</td>
  </tr>
  <tr id="tdata">
    <td><input type="checkbox" value="440" id="achk"></td>
    <td>LMN</td>
    <td>6</td>
  </tr>
</tbody>

Get Array like this for it respective Checkbox is checked.

Array(
'<tr id="tdata">
    <td><input type="checkbox" value="440" id="achk"></td>
    <td><input type="textbox" value="ABC"></td>
    <td><input type="textbox" value="2"></td>
  </tr>',
'<tr id="tdata">
    <td><input type="checkbox" value="440" id="achk"></td>
    <td><input type="textbox" value="PQR"></td>
    <td><input type="textbox" value="4"></td>
  </tr>'
)
È stato utile?

Soluzione

You can use jQuery .find and .child functions, you can also check a possible similar question here, may also help.

Altri suggerimenti

Here is a solution or you can check here at jsfiddle

$(function () {

var pids = Array();                               
$('#answer tbody').find('input[type="checkbox"]:checked').closest('tr').map(function(){
    var trindex = $(this).index();
    var trhtml = $('#answer tbody tr')[trindex].outerHTML;
    pids.push(trhtml);
});

});

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top