[英]Make a search menu disappear when the search field loses focus, but still allow user to click on links
On my website I have a search box (text input field). 在我的网站上,我有一个搜索框(文本输入字段)。 When the user clicks on it and starts typing text a menu of links appears.
当用户点击它并开始键入文本时,会出现一个链接菜单。 The menu appears via JQuery - The following command makes the menu appear:
菜单通过JQuery显示 - 以下命令使菜单显示:
".focus(function() {
$("#instant_search_wrapper").show();
}); "
When the user clicks off the search box, I would like the menu to disappear. 当用户点击搜索框时,我希望菜单消失。
The easiest way of doing this would be to be use the following command: 最简单的方法是使用以下命令:
".blur(function() {
$("#instant_search_wrapper").hide();
});"
However, if I do this, then when the user clicks on a link in the menu, the text input field loses focus and so the menu disappears before the user is taken to the select page. 但是,如果我这样做,那么当用户点击菜单中的链接时,文本输入字段会失去焦点,因此菜单会在用户进入选择页面之前消失。 How can I make it so the menu disappears when the search field loses focus, (but if the user clicks on a link before the search field loses focus, s/he is still able to be taken to the link)?
当搜索字段失去焦点时,我怎样才能使菜单消失(但如果用户在搜索字段失去焦点之前点击链接,他/她仍然可以被带到链接)?
You need to bind the click to body for hiding 您需要将单击绑定到正文以进行隐藏
$(document).click(function() {
$("#instant_search_wrapper").hide();
});
Can you be more specific, I don't understand the question. 你能更具体一点,我不明白这个问题。 I checked your site and when I start typing something, a modal box style menu with the results is showed.
我检查了你的网站,当我开始输入内容时,会显示一个带有结果的模式框样式菜单。 Then if I blur the input the box still there.
然后,如果我模糊输入框仍然存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.