2013-01-21 50 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。

你可能想這是什麼:

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

嘗試做

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

你的範圍可能與您當前選擇的限制。

相關問題