如何从jQuery中的输入字段中删除焦点? [英] How to remove focus from input field in jQuery?

查看:144
本文介绍了如何从jQuery中的输入字段中删除焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用以下行加载页面时,我将焦点放在某个输入字段上:

I am setting the focus on a certain input field when loading a page using the following line:

$('#myInputID').focus();

当悬停在某个元素上时,是否可以撤消或移除此焦点? (离开此元素后不必重置焦点.)

Is there a way that I can undo or remove this focus when hovering over a certain element? (The focus does not have to be reset after leaving this element.)

我在jQuery中找不到与上述功能相反的功能,否则将无法在此工作.

I couldn't find a function that is the opposite to the above in jQuery or would otherwise work here.

推荐答案

使用 .blur() .

Use .blur().

当模糊事件失去焦点时,它会发送到该元素.最初,此事件仅适用于表单元素,例如<input>.在最近的浏览器中,事件的域已扩展为包括所有元素类型.元素可以通过键盘命令(例如Tab键)或单击页面其他位置的鼠标来失去焦点.

The blur event is sent to an element when it loses focus. Originally, this event was only applicable to form elements, such as <input>. In recent browsers, the domain of the event has been extended to include all element types. An element can lose focus via keyboard commands, such as the Tab key, or by mouse clicks elsewhere on the page.

$("#myInputID").blur(); 

这篇关于如何从jQuery中的输入字段中删除焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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