jquery에서 "this"및 ".parent()"를 사용하면 간단한 div 또는 datatables를 지나칠 때 약간 혼란스러워집니다. 나는 다음과 같은 구조의 테이블을 가지고 :JQuery .parent click
<table class="table1">
<tbody>
<tr>
<div class="detail">
<table>
<thead></thead>
<tbody>
<tr>
<td>
<img class="picture_open" src="../location">
</td></tr></tbody></table></div></tr></tbody></table>
가 난 할 노력하고있어 것은 잡을 수있을 것이다 IMG에 클릭 기능을 가지고있다 (필자는 클래스 또는 ID의 이름을 바꿀 수 없습니다) 완전한 RowElement
내가 지금 무엇을 가지고 : 나는 위의이 코드가 출력합니다 그러나
이$(".table1 tbody tr td img.picture_open").live('click', function() {
var overallTable = jQuery(this).parent("table").dataTable();
console.log("overallTable: " + overallTable);
var elementRow = this.parentNode.parentNode;
console.log("elementRow: " + elementRow);
var rowData = overallTable.fnGetData(elementRow);
console.log("rowData: " + rowData);
if (this.src.match('img_name'))
{
//kills the table that was created if that row is opened
}
else
{
//runs ajax call to create another table since row is NOT opened
}
});
: [개체 개체] elementRow : [객체 HTMLTableRowElement] 형식 오류 : '널 (null)'는 객체가 아닌 는 overallTable ('oSettings.aoData'평가)
내 문제는 $ (this)가 잘못 되었습니까? ("picture_open"클래스로 img를 가져 오지 못합니다) 또는 내 overallTable 변수가 .parent()로 잘못 설정 되었습니까? 또는 내 elementRow 변수가 parentNode로 잘못 설정 되었습니까? 내 오류를 명확히하는 데 도움이 될 것입니다.
감사합니다.
을 내가 사용하려는 생각 ((http://api.jquery.com/closest) 대신 .parent'의 ['()'.closest])' – Blazemonger
당신이하려는 것은 매우 불분명합니다. 'this'는 img 요소가 될 것이고, 이미'.parentNode.parentNode'를 가지고 행을 얻고 있습니다. –
@Blazemonger : 나는 당신이 옳다고 생각합니다. .closest()에 대한 설명서를 읽은 후에는 .parent()보다 더 적합하다고 생각합니다. – dkengaroo