2013-08-12 34 views
0

从下面的代码,我不能得到input[radio]检查表中选定的行。以下代码使用HTML5JQuery 1.10.2HTML5 tr与无线电行选择

<!DOCTYPE HTML> 
<html> 
    <head> 
     <style type="text/css"> 
      input[type="radio"] { 
       margin: 10px; 
      } 
     </style> 
     <script src="jquery-1.10.2.min.js" /> 
     <script>    
      $(function() { 
       $("#table_list tr").click(function() { 
        $(this).find("td input:radio").prop("checked", true); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <table id="table_list"> 
      <thead> 
       <th></th> 
       <th>Name</th> 
       <th>Email</th>    
      </thead> 
      <tbody> 
       <tr> 
        <td><input type="radio" name="record"/></th> 
        <td>Sample1</td> 
        <td>[email protected]</td> 
       </tr> 
       <tr> 
        <th><input type="radio" name="record"/></th> 
        <td>Sample1</td> 
        <td>[email protected]</td>      
       </tr> 
      </tbody> 
     </table>   
    </body> 
</html> 
+0

你能提供的jsfiddle?首先,你需要给你的收音机一个价值,以便以后评估它们。 – Pouki

+2

解决您的标记,它会工作(你有'内'​​'等''标签',也是你的''没有'') – billyonecan

+1

HTML这里固定的http:// jsbin.com/adesux/1/edit – Anton

回答

3

你的第一输入处于td,第二个是在一个th。你必须从你的输入选择删除tdworking codepen

$(function() { 
    $("#table_list tr").click(function() { 
     $(this).find("input:radio").prop("checked", true); 
    }); 
}); 

所附的JavaScript将工作两个。另一个选择是仅改变thtd并保持你的选择会是这样。

注意:您在评论中提到的人有几个标记问题。 (在thead忘记tr