2013-05-10 104 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

相關問題