当聚焦时,我们可以这样做:
$('#target').focus(function(){$(this)..}); 因为"this“只是一个焦点($(this) == $('#target'))。
但是不能对“模糊”做同样的事情,因为$(this) != $('#target')。
怎样做才是正确的呢?
注意:在我的应用程序中,我不能给目标分配id,这里的'# target‘只是为了说明。
发布于 2009-09-11 07:37:33
模糊将保持你所期望的上下文:
$("#target").blur(function() {
$(this).text("See? It works!");
});发布于 2009-09-11 07:15:17
var foo = $('target');
foo.focus(function(){foo.....});匿名函数将充当闭包,并将记住foo的值。
发布于 2009-09-11 07:35:49
我可以用模糊来访问'this‘,下面的代码运行正常...
$(".aClass").blur(
function(){
alert($(this).attr("id"));
});https://stackoverflow.com/questions/1409424
复制相似问题