2013-05-10 103 views
0

我需要检查/取消选中了某个行内部存在下表体被点击时,随时随地行内除了一个链接的复选框。我试图通过使用jQuery的道具使它工作,但有些东西不能正常工作。如何检查/取消选中复选框并单击表行

我有一个表结构如下图所示:

<table id="anywhere_click"> 
<thead> 
    <tr> 
     <th><input type="checkbox" onclick="selectAll('myDataID[]');" /></th> 
     <th>Title</th> 
     <th>Details</th> 
    </tr> 
</thead> 
<tbody> 
    <tr> 
     <td><input type="checkbox" name="myDataID[]" value="1" /></td> 
     <td>Stackoverflow</td> 
     <td>Some text here....</td> 
    </tr> 
    <tr> 
     <td><input type="checkbox" name="myDataID[]" value="2" /></td> 
     <td>Google</td> 
     <td> 
      <a href="aaa.html">This is a Link</a><br /> 
      Some text here....<br /> 
      <img src="something.jpg" /> 
     </td> 
    </tr> 
    <tr> 
     <td><input type="checkbox" name="myDataID[]" value="3" /></td> 
     <td>test</td> 
     <td>Some text here....</td> 
    </tr> 
</tbody> 
</table> 
+0

请把你的jQuery代码在这里也 – RL89 2013-05-10 09:34:15

回答

6
$('#anywhere_click tbody tr').click(function (e) { 
    if(!$(e.target).is('#anywhere_click td input:checkbox')) 
    $(this).find('input:checkbox').trigger('click'); 
}); 

$('#anywhere_click tr a').click(function (e) { 
    e.stopPropagation(); 
}); 
+0

您的演示不起作用完全一样我想要的。它应该只在表格下的表格行被点击时才起作用。在你的例子中,位于表头的表格行也在激活这个功能。此外,当我直接点击复选框时,它不起作用。 – Prakash 2013-05-10 09:46:38

+0

试试这个 - http://jsfiddle.net/mohammadAdil/Vc9Cd/1/ – 2013-05-10 09:50:06

+0

这也有同样的问题。 – Prakash 2013-05-10 09:59:36

0

如果选中时,该网站的加载。

你必须签入的标签<td><input type="checkbox" name="myDataID[]" value="3" /></td> 补充。

<td><input type="checkbox" name="myDataID[]" value="3" checked /></td> 

用你想要选中和取消选中的按钮。

信息:Information

和示例:Examble with button checked and unchecked

相关问题