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

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

问题描述

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

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.

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

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

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.

我想知道如何以编程方式关闭下拉列表而无需关注另一个输入。

推荐答案

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

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.

这个问题反过来说:以编程方式打开一个下拉菜单

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

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

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

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天全站免登陆