用Javascript / jQuery以编程方式关闭SELECT下拉列表 [英] Close a SELECT dropdown list programatically with Javascript/jQuery

查看:103
本文介绍了用Javascript / jQuery以编程方式关闭SELECT下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用单一值初始化的下拉菜单。当用户点击它时,单个元素将被删除,并添加一个新的元素来说明加载,然后向服务器发出AJAX调用,并在返回时将新值添加到控件中。



问题是控件在更新时保持打开状态,我想关闭它。



这是一个例子: http://jsfiddle.net/vtortola/CGuBk/2/



示例的AJAX没有获取数据,可能是因为我在调用jsfiddle api时出错,但它显示了 SELECT 在更新期间保持打开状态。



我想知道如何以编程方式关闭下拉列表而无需专注于其他输入。

我不确定其他人,但我正在使用Chrome的最新稳定版本,而其他答案都不涉及 .blur()为我工作。



这个问题提出了相反的问题:以编程方式打开下拉菜单



似乎得到的结论是,由于浏览器的方式,这是不可能的处理字段元素点击。



更好的解决方案是用一个纯HTML代替下拉,并在需要时用一个简单的 .hide隐藏它()命令。


I have a dropdown that is initialized with one single value. When the user clicks it, the single element is removed and a new element is added saying "Loading", then an AJAX call is issued to the server and when returns, the new values are added to the control.

The problem is that the control remains open while updating, and I would like to close it.

This is an example : http://jsfiddle.net/vtortola/CGuBk/2/

The example's AJAX does not get data probably because something wrong I am doing when calling the jsfiddle api, but it shows how the SELECT remains open during update.

I want to know how to close the dropdown list programatically w/o focus in another input.

Cheers.

解决方案

I'm not sure about anyone else, but I'm using the latest stable build of Chrome, and none of the other answers involving .blur() work for me.

This question asks the inverse: Programmatically open a drop-down menu

The conclusion that seemed to be obtained is that it's not possible due to the way the browser handles field element clicks.

A better solution would be to replace the dropdown with a pure HTML one and hide it when needed with a simple .hide() command.

这篇关于用Javascript / jQuery以编程方式关闭SELECT下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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