Как получить значение проверенного переключателя и остальных td, но не включать переключатель, который не был проверен (в tr)

У меня есть код js для получения первого значения td, но я хочу получить значение проверенного переключателя и оставшегося значения td, но не включать переключатель, который не был проверен (в tr) … ………………………………………….. ………………………………………….. ……………………

"my js" $(".hit").click(function(){ var str="";var counter=0; $.each($("input[name^='flight']:checked").closest("td").siblings("td:first-child"), function () { if(counter != 0 ) str +="&"; str +="id"+(counter+1)+"=" + $(this).text(); counter++; }); console.log(str); //location.href = "guestdetails.php?" + str; }); "my php" foreach ($query1 as $flights) { echo "<tr>"; echo "<td>".$flights['id']."</td>"; echo "<td>".$flights['depart']."</td>"; echo "<td>".$flights['arrive']."</td>"; echo "<td>".$flights['airport']."</td>"; echo "<td>".$flights['duration']."</td>"; echo "<td><label for=lbl3> <input type='radio' checked id='lbl3' name='flight1[]' class='hit1' value='".$flights['flyonly']."'> PHP ".number_format($flights['flyonly'])."</label></td>"; echo "<td><label for=lbl4> <input type='radio' checked id='lbl4' name='flight1[]' class='hit1' value='".$flights['flybaggage']."'>PHP ".number_format($flights['flybaggage'])."</label></td>"; echo "</tr>"; } 

Вам нужно проверить, есть ли у td входной тип радио, и он проверяется, а затем получает значение else, если это не радио, получить текст.

 $(".hit").click(function(){ var $row = $('table').find('tr:first'); var th=[]; $.each($row.find('th'), function (index) { th[index]=$(this).text(); }); var str="";var counter=0;var headCounter=th.length; $.each($("input[name^='flight']:checked").closest("tr").find('td'), function (index) { if($(this).find('input:radio').length && $(this).find('input:radio').is(':checked')){ if(counter != 0 ) str +="&"; str +="id"+(counter+1)+"=" + $(this).find('input:radio').val(); counter++; // adding Th here str +="&"; str +="id"+(counter+1)+"=" + th[index%headCounter]; counter++; } if($(this).find('input:radio').length == 0){ if(counter != 0 ) str +="&"; str +="id"+(counter+1)+"=" + $(this).text(); counter++; } }); console.log(str); //location.href = "guestdetails.php?" + str; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr><th>Head1</th><th>Head2</th><th>Head3</th><th>Head4</th></tr> <tr> <td>f</td> <td>f</td> <td><input type="radio" name="flight1[]" value='1'></td> <!-- FIND THIS --> <td><input type="radio" name="flight1[]" value='11'></td> <!-- FIND THIS --> </tr> <tr> <td>f1</td> <td>f</td> <td><input type="radio" name="flight2[]" value='12'></td> <!-- FIND THIS --> <td><input type="radio" name="flight2[]" value='112'></td> <!-- FIND THIS --> </tr> <tr> <td>f2</td> <td>f</td> <td><input type="radio" name="flight3[]" value='13'></td> <!-- FIND THIS --> <td><input type="radio" name="flight3[]" value='113'></td> <!-- FIND THIS --> </tr> </table> <button type="button" class="hit">hit</button>