jQuery失去焦点事件 [英] jQuery lose focus event

查看:132
本文介绍了jQuery失去焦点事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示一个容器,如果输入字段获得焦点,并且 - 这是实际的问题 - 隐藏容器,如果焦点丢失。 jQuery的焦点有一个相反的事件吗?

一些示例代码:

 < input type =textvalue =name =filterid =filter/> 

< div id =options>一些很酷的选项< / div>

< script type =text / javascript>
$('#options')。hide();
$ b $('#filter')。focus(function(){
$('#options')。appear();
});
< / script>

我想要做的是这样的:

  $('#filter')。focus_lost(function(){
$('#options')。hide();
});


解决方案

使用

 

blur(function(){
$('#options')。hide();
});


I'm trying to show up a container if a input field gets the focus and - that's the actual problem - hide the container if focus is lost. Is there an opposite event for jQuery's focus?

Some example code:

<input type="text" value="" name="filter" id="filter"/>

<div id="options">some cool options</div>

<script type="text/javascript">
  $('#options').hide();

  $('#filter').focus(function() {
    $('#options').appear();
  });
</script>

And what I'd like to do is something like this:

$('#filter').focus_lost(function() {
  $('#options').hide();
});

解决方案

Use blur event to call your function when element loses focus :

$('#filter').blur(function() {
  $('#options').hide();
});

这篇关于jQuery失去焦点事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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