如何获取已检查的单选按钮的值和剩余的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 ""; echo "".$flights['id']." "; echo "".$flights['depart']." "; echo "".$flights['arrive']." "; echo "".$flights['airport']." "; echo "".$flights['duration']." "; echo " "; echo " "; echo " "; }
您需要检查td是否具有输入类型无线电并且检查它然后获取值否则如果它不是无线电获取文本。
$(".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; });
Head1 Head2 Head3 Head4 f f f1 f f2 f