如何在blur或focusout事件里得到即将得到焦点的元素?另外这两个事件有什么区别?_html/css_WEB-ITnose
回复讨论(解决方案)
笨办法是
输入框 失去焦点后
settimeout 一段时间后 弹出的列表框 消失 这样可以给你点一下的机会
setTimeout延时隐藏table,再写table的mouseenter事件,清除定时器,mouseleave事件隐藏table
var timer;
$(input).blur(function(){
timer = setTimeout(function(){
$(table).hide();
},200);
});
$(table).mouseenter(function(){
if(timer) clearTimeout(timer);
});
$(table).mouseleave(function(){
$(table).hide();
});
能看明白?
setTimeout延时隐藏table,再写table的mouseenter事件,清除定时器,mouseleave事件隐藏table
var timer;
$(input).blur(function(){
timer = setTimeout(function(){
$(table).hide();
},200);
});
$(table).mouseenter(function(){
if(timer) clearTimeout(timer);
});
$(table).mouseleave(function(){
$(table).hide();
});
能看明白?
你这话说的,有什么不明白的? 问题已经解决。我还想问的是blur和focusout有哪些区别,网上找不到好的资源。
setTimeout延时隐藏table,再写table的mouseenter事件,清除定时器,mouseleave事件隐藏table
var timer;
$(input).blur(function(){
timer = setTimeout(function(){
$(table).hide();
},200);
});
$(table).mouseenter(function(){
if(timer) clearTimeout(timer);
});
$(table).mouseleave(function(){
$(table).hide();
});
能看明白?
只是有一点我不懂,就是我在table的td内添加函数
td.onclick = function () { if(timer) clearTimeout(timer); source.value = this.innerHTML; //注意TextBox的innerHTML为空,因为text位于元素内部 $("#" + tableId).remove(); }
虽然也在TextBox的blur函数内设置了延时定时器
$("#txtEmail").blur(function(event) { timer = setTimeout(function () { $("#tableEmail").remove() }, 200); //异步,立即返回 //设置定时器延时让table得到焦点并处理后再消失,而且延时不能太短也不能太长 })
但是如果不在td.onclick内不写$("#" + tableId).remove(),table并不会消失,也就是并没有执行定时器内的延时函数,难道延时内只要有执行过程就会阻塞执行定时器内的延时函数导致其不执行吗?
setTimeout延时隐藏table,再写table的mouseenter事件,清除定时器,mouseleave事件隐藏table
var timer;
$(input).blur(function(){
timer = setTimeout(function(){
$(table).hide();
},200);
});
$(table).mouseenter(function(){
if(timer) clearTimeout(timer);
});
$(table).mouseleave(function(){
$(table).hide();
});
能看明白?
只是有一点我不懂,就是我在table的td内添加函数
td.onclick = function () { if(timer) clearTimeout(timer); source.value = this.innerHTML; //注意TextBox的innerHTML为空,因为text位于元素内部 $("#" + tableId).remove(); }
虽然也在TextBox的blur函数内设置了延时定时器
$("#txtEmail").blur(function(event) { timer = setTimeout(function () { $("#tableEmail").remove() }, 200); //异步,立即返回 //设置定时器延时让table得到焦点并处理后再消失,而且延时不能太短也不能太长 })
但是如果不在td.onclick内不写$("#" + tableId).remove(),table并不会消失,也就是并没有执行定时器内的延时函数,难道延时内只要有执行过程就会阻塞执行定时器内的延时函数导致其不执行吗?
因为先执行了input的blur事件,再执行td的onclick事件,于是在onclick的时候,先clear掉了timer,所以就不会执行setTimeout里面的函数了。
至于你问的fousout跟blur事件有什么区别,我没接触过fousout,我估计fousout事件应该会比blur多一个属性targetElement||toElement,类似mouseout,可以获取fousout后哪个对象获得焦点。
setTimeout延时隐藏table,再写table的mouseenter事件,清除定时器,mouseleave事件隐藏table
var timer;
$(input).blur(function(){
timer = setTimeout(function(){
$(table).hide();
},200);
});
$(table).mouseenter(function(){
if(timer) clearTimeout(timer);
});
$(table).mouseleave(function(){
$(table).hide();
});
能看明白?
只是有一点我不懂,就是我在table的td内添加函数
td.onclick = function () { if(timer) clearTimeout(timer); source.value = this.innerHTML; //注意TextBox的innerHTML为空,因为text位于元素内部 $("#" + tableId).remove(); }
虽然也在TextBox的blur函数内设置了延时定时器
$("#txtEmail").blur(function(event) { timer = setTimeout(function () { $("#tableEmail").remove() }, 200); //异步,立即返回 //设置定时器延时让table得到焦点并处理后再消失,而且延时不能太短也不能太长 })
但是如果不在td.onclick内不写$("#" + tableId).remove(),table并不会消失,也就是并没有执行定时器内的延时函数,难道延时内只要有执行过程就会阻塞执行定时器内的延时函数导致其不执行吗?
因为先执行了input的blur事件,再执行td的onclick事件,于是在onclick的时候,先clear掉了timer,所以就不会执行setTimeout里面的函数了。
至于你问的fousout跟blur事件有什么区别,我没接触过fousout,我估计fousout事件应该会比blur多一个属性targetElement||toElement,类似mouseout,可以获取fousout后哪个对象获得焦点。
我所知道的有srcElement,fromElement,toElement,target和relatedTarget,但是好像都不能得到即将得到焦点的元素,不知道他们有什么特殊含义。
srcElement|| target 当前目标元素
fromElement || relatedTarget 从何元素进入当前元素
toElement || relatedTarget 从当前元素进入到何元素
简单点说就是:
我是谁
我从何而来
我去往何方
srcElement|| target 当前目标元素
fromElement || relatedTarget 从何元素进入当前元素
toElement || relatedTarget 从当前元素进入到何元素
简单点说就是:
我是谁
我从何而来
我去往何方
srcElement和target属性在blur或focusout中可用,其它三个不行;但是在onmouseover和onmouseout中所有属性都可用。所以确实不能在此获得即将得到焦点的元素了,只能采用延时了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex
