jQuery:与.focus()相反或如何从输入字段中删除焦点 [英] jQuery: Opposite to .focus() or How to remove focus from input field

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

问题描述



  $('#myInputID ')。焦点(); 

有没有办法让我可以撤销或移除这个焦点时,悬停在某个元素
(离开这个元素后焦点不需要重新设置)

我在jQuery中找不到与上面相反的函数否则会在这里工作。



有人可以帮我解决这个问题吗?

解决方案

> .blur()


模糊事件失去焦点时发送给元素。本来,这个事件只适用于表单元素,例如< input> 。在最近的浏览器中,事件的领域已经扩展到包含所有的元素类型。元素可以通过键盘命令(如Tab键)或通过在页面上的其他位置点击鼠标来失去焦点。




  $( #myInputID)模糊(); 


I set 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.)

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

Can someone help me with this?

解决方案

Use .blur().

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:与.focus()相反或如何从输入字段中删除焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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