0
我想获取对单元格的引用,它看起来为空。如果我正确理解它,我应该能够引用该变量。正确?Javascript关闭范围问题
$('td[someAttr]').mouseenter(function(cell) {
var timeoutId = setTimeout(function() {
// what should variable cell be?
}, 1000);
});
OR
$('td[someAttr]').mouseenter(function(cell) {
var timeoutId = setTimeout(function() {
// what should variable cell be?
}, 1000, cell);
});
UPDATE:这是显而易见的,但我问其原因,这是因为cell.pageX会,如果你有是不确定的:,
$('td[someAttr]').mouseenter(function() {
var cell = this; //
var timeoutId = setTimeout(function() {
alert(cell.pageX); // cell.pageX will return null
}, 1000);
});
但是,如果你有:
$('td[someAttr]').mouseenter(function(cell) {
alert(cell.pageX); // works fine as cell.pageX will have correct value.
});
这是显而易见的,但我之所以问这是因为cell.pageX是未定义的,我会发布更新并告诉你我的意思。 – 2009-06-25 21:46:34