你如何清除焦点在JavaScript? [英] How do you clear the focus in javascript?

查看:147
本文介绍了你如何清除焦点在JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这应该不是那么难,但我无法在Google上找到答案。



我想要执行一段JavaScript,不管提前知道哪个元素的焦点在哪个元素上。它必须工作在Firefox 2以及更现代的浏览器。

是否有一个好办法做到这一点?

解决方案

.focus()然后 .blur()否则在您的网页上任意。因为只有一个元素可以获得焦点,所以它被转移到该元素,然后被移除。


I know this shouldn't be that hard, but I couldn't find the answer on Google.

I want to execute a piece of javascript that will clear the focus from whatever element it is on without knowing ahead of time which element the focus is on. It has to work on firefox 2 as well as more modern browsers.

Is there a good way to do this?

解决方案

.focus() and then .blur() something else arbitrary on your page. Since only one element can have the focus, it is transferred to that element and then removed.

这篇关于你如何清除焦点在JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆