我將jQuery和dataTables插件一起使用。 dataTables提供了打開和關閉行的功能(意味着可以在常規行下打開附加信息行)。jQuery HTMLElement打包/解包
從http://datatables.net/api我得到了下面的良好工作示例:
$(document).ready(function() {
var oTable;
// 'open' an information row when a row is clicked on
$('#example tbody tr').click(function() {
if (oTable.fnIsOpen(this)) {
oTable.fnClose(this);
} else {
oTable.fnOpen(this, "Temporary row opened", "info_row");
}
});
oTable = $('#example').dataTable();
});
現在我想不添加單擊處理程序到整個行,但該行的元素:
$("#openCompliantsTable .icon-comment").click(…
但當然this
現在不是指tr
元素,而是指某個子元素。我嘗試更改代碼是將this
替換爲$(this).parent().parent().get()
,但沒有成功。
後來我發現,其實this
似乎不是一樣$(this).get()
,即使雙方都[object HTMLElement]
對象,這讓我吃驚。
任何可能的結果?
編輯: 我的HTML表看起來像這樣:
<table id="openCompliantsTable" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Reklamationsnummer</th>
<th>Reklapositionsnummer</th>
...
<th>Status</th>
<th>Aktion</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>1</td>
...
<td>offen</td>
<td><i class="icon-ok"></i><i class="icon-trash"></i><i class="icon-flag"></i><i class="icon-comment"></i></td>
</tr>
...
</tbody>
</table>
你確定'$(this).parent()。parent()'找到TR元素嗎? – 2012-02-04 09:50:53
是的,我可以添加一些CSS類。 – thorink 2012-02-04 09:55:05