pil*_*ght 41 javascript jquery events javascript-events onblur
假设我这样做:
$(target).blur(function(e){
//do stuff
});
Run Code Online (Sandbox Code Playgroud)
有没有办法获取被点击的对象以触发模糊操作?
我尝试使用e.target
,但这似乎是返回附加到模糊操作的对象而不是单击的对象.
blo*_*ead 46
诀窍是等待一个额外的滴答:
$(el).blur(function (event) {
// If we just hangout an extra tick, we'll find out which element got focus really
setTimeout(function(){
document.activeElement; // This is the element that has focus
},1);
})
Run Code Online (Sandbox Code Playgroud)
dar*_*ryl 37
如果我理解你的问题,应该这样做:
$(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);
});??
});
Run Code Online (Sandbox Code Playgroud)
在事件处理程序内部,this
将是事件绑定的元素,并且e.target
将是触发事件的元素(可能与否相同this
).
你正在处理一个blur
事件,而不是一个click
事件.因此,在您的活动中,您将拥有您blur
编辑的元素.如果你想要click
ed元素,你需要另一个事件来获得它.
blur
可以由其他事件触发,例如聚焦某事; 不只是点击某事.所以,没有办法让元素"引起模糊".
归档时间: |
|
查看次数: |
38001 次 |
最近记录: |