0
특정 셀을 클릭 할 때 셀 인덱스를 가져올 수 있도록 테이블의 셀에 리스너를 추가하고 있습니다. 그러나 나는 크롬에서 행 색인의 가치를 얻을 수 없습니다. 이것은 IE10과 Firefox에서 잘 작동합니다. 코드는 다음과 같습니다.parentNode.rowIndex가 크롬에서 작동하지 않습니다.
function AttachEvents() {
var cls = document.getElementById("TableContents").getElementsByTagName("td");
for (var i = 0; i < cls.length; i++) {
if (cls[i].addEventListener) {
cls[i].addEventListener("click", alertRowCell, false);
} else if (cls[i].attachEvent) {
cls[i].attachEvent("onclick", alertRowCell);
}
}
}
function alertRowCell(e) {
var cell = e.target || window.event.srcElement;
//alert(cell.cellIndex + ' : ' + cell.parentNode.rowIndex);
if (cell.cellIndex == 1) {
alert(" The row index is " + cell.parentNode.rowIndex);
highlight();
}
}
Chrome에서 어떻게 해결할 수 있습니까?
오류 :
이 예제를 시도
? Chrome에서'cell.parentNode'는 어떤 요소입니까? – alex어떻게 작동하지 않는지 설명해 주시겠습니까? 그래서 우리는 스스로를 찾아야하지 않습니까? –
크롬을 제외하고 cell.parentNode.Rowindex는 클릭 된 실제 행을 반환합니다. 크롬에서 -1을 반환합니다. –