Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

javascript - jQuery失去焦点事件(jQuery lose focus event)

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?(是否存在jQuery关注的相反事件?) 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(); });   ask by xijo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use blur event to call your function when element loses focus :(当元素失去焦点时,使用blur事件调用函数:)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...