2013-01-21 5 views
1

다음 코드로 작업 중이며 일부 테이블 데이터의 html을 수정하려고합니다. 그러나 $(this).html()의 값은 항상 정의되지 않은 것처럼 보입니다. 나는 왜 그런지 이해하지 못한다. 누군가 제발 설명해 줄래?정의되지 않은 이유는 무엇입니까?

$(document).on('click',"td",function() { 
     //console.log($(this).html()); 
    }).focusout(function(){ 
     console.log($(this).html()); //undifined 
}); 
+3

쉘던이 결코 설명을 요청하지 않았다고 생각 했나요? – Artyom

답변

1

이벤트를 문서에 바인딩 한 다음 HTML을 가져 오는 중입니다. 문서에 html이 없습니다.

은 당신이 아마 원하는 것은 이것이다 : 현재 선택으로 제한 될 수 있습니다

$('td').on('click', function() { 
}).focusout(function(){ 
    console.log($(this).html()); //undifined 
}); 

귀하의 범위를하고

$(document).on('click',"td",function() { 
    //console.log($(this).html()); 
}).on('blur','td',function(){ 
    console.log($(this).html()); //not undifined :-) 
}); 
관련 문제