0

对焦时,我们可以这样做:

$('#target').focus(function(){$(this)..}); 

因为“this”只是关注的那个($(this) == $('#target'))。

但不能对“模糊”做同样的事情,因为$(this) != $('#target').

如何以正确的方式做到这一点?

注意:在我的应用程序中,我无法为目标分配 id,此处的“#target”仅用于说明。

4

4 回答 4

1

Blur 将保持您所期望的上下文:

$("#target").blur(function() {
    $(this).text("See? It works!");
});
于 2009-09-11T07:37:33.003 回答
0
var foo = $('target');
foo.focus(function(){foo.....});

匿名函数将充当闭包并记住 foo 的值。

于 2009-09-11T07:15:17.350 回答
0

我可以通过模糊访问“这个”,以下代码工作正常......

$(".aClass").blur(
  function(){
    alert($(this).attr("id"));
});
于 2009-09-11T07:35:49.077 回答
0

Event/blur触发每个匹配元素的模糊事件,并且 $(this) 只返回被模糊的那个。

jQuery("#target").blur(function() {
  console.log( jQuery(this) );
});

使用萤火虫。它还将一个名为“console”的全局变量添加到 Firefox 中加载的所有网页。在这种情况下,“console.log”会向控制台写入一条消息。

于 2009-09-11T08:32:37.027 回答