获取触发jquery blur()事件的点击对象 [英] Get the clicked object that triggered jquery blur() event
本文介绍了获取触发jquery blur()事件的点击对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我这样做:
$(target).blur(function(e){
//做东西
});
有没有办法获取点击的对象以触发模糊动作? / p>
我尝试使用 e.target
,但似乎是返回附加到模糊动作的对象,而不是点击的对象。
解决方案
如果我正确理解您的问题,应该这样做:
$(function(){
var clicky;
$(document).mousedown(function(e){
//最新的元素点击
clicky = $(e.target);
});
//当模糊的时候'clicky == null',我们知道它不是由点击
//引起的,但也可能通过按Tab键
$(document).mouseup(function(e){
clicky = null;
}) ;
$(target).blur(function(e){
console.log(clicky);
});
} );
Suppose I do this:
$(target).blur(function(e){
//do stuff
});
Is there a way to fetch the object that was clicked on in order to trigger the blur action?
I tried using e.target
, but that appears to be returning the object attached to the blur action rather than the clicked object.
解决方案
If I understand your question correctly, this should do it:
$(function() {
var clicky;
$(document).mousedown(function(e) {
// The latest element clicked
clicky = $(e.target);
});
// when 'clicky == null' on blur, we know it was not caused by a click
// but maybe by pressing the tab key
$(document).mouseup(function(e) {
clicky = null;
});
$(target).blur(function(e) {
console.log(clicky);
});
});
这篇关于获取触发jquery blur()事件的点击对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文