2011-06-16 20 views
2

简单的问题是我对JQuery理解的一个缺陷。在嵌套JQuery中引用原始html元素

$('input').focus(function() { 

    $('.popup').click(function() { 
     //How do I reference the original input that 
     //triggered the focus event here?    
    }); 
}); 

你可以从标题说,我有问题寻找一个答案......

回答

4

你可以这样添加引用:

$('input').focus(function() { 
    var originalInput = $(this); 
    $('.popup').click(function() { 
     console.log(originalInput.val());   
    }); 
}); 
1
$('input').focus(function() { 
    var orig = $(this); 
    $('.popup').click(function() { 
     //How do I reference the original input that 
     //triggered the focus event here?    
     console.log(orig); 
    }); 
});