题
聚焦时,我们可以做类似的事情:
$('#target').focus(function(){$(this)..});
因为“这个”只是集中注意力的那个( $(this)== $('#target')
)。
但是对于“模糊”不能做同样的事情,因为 $(this)!= $('#target')
。
如何正确地做到这一点?
注意: 在我的应用程序中,我无法为目标指定一个id,这里的“#target”仅用于说明。
解决方案
模糊将保持您期望的上下文:
$("#target").blur(function() {
$(this).text("See? It works!");
});
其他提示
var foo = $('target');
foo.focus(function(){foo.....});
匿名函数将充当闭包,并将记住foo的值。
我可以通过模糊访问'this',以下代码正常工作......
$(".aClass").blur(
function(){
alert($(this).attr("id"));
});
不隶属于 StackOverflow