[英]How do I close a combo box with javascript?
I'm pretty new to javascript, so please forgive my ignorance. 我对javascript很陌生,所以请原谅我的无知。 I'm trying to do something that seems like it should be incredibly simple...close a combo box. 我正在尝试做一些看起来非常简单的事情...关闭组合框。 However, when I use the hide() function, it not only closes the combo box, but it removes it entirely. 但是,当我使用hide()函数时,它不仅关闭组合框,而且将其完全删除。 Is there any way to just close it? 有什么办法可以关闭它吗?
EDIT: 编辑:
Here's the actual code I'm using 这是我正在使用的实际代码
$(window).ready(function ()
{
$('#comboBox .dropdown-menu').mouseleave(function ()
{
$("#comboBox").hide();
});
});
This removes the combo box from the page when the mouse leaves the open combo box. 当鼠标离开打开的组合框时,这将从页面上删除组合框。 If I replace hide with blur, nothing happens at all. 如果我将“ hide”替换为“ blur”,则什么也不会发生。
Edit 2: 编辑2:
Here's the code for my actual list: 这是我的实际列表的代码:
<div class="btn-group" id="comboBox">
<button class="btn btn-custom-top dropdown-toggle" data-toggle="dropdown"><span class="caption"></span><span class="caret"></span></button>
<ul class="dropdown-menu">
</ul>
</div>
Edit 3: 编辑3:
Alright, I was obviously confused about what I was doing. 好吧,我对自己的工作明显感到困惑。 No surprise there, as I'm very new to all this. 在那里就不足为奇了,因为我对这一切都很陌生。 It's not actually a combo box that I'm trying to close. 实际上,这不是我要关闭的组合框。 It's a bootstrap dropdown button type, which doesn't really have the same behavior as a combo box. 这是引导程序下拉按钮类型,实际上与组合框的行为不同。 It's looking like there is no function ready-made to do what I want. 似乎没有现成的功能可以执行我想要的操作。
如果您正在谈论DOM select
元素,那么最好的办法就是调用blur()
,它将关闭它。
您应该调用其blur
事件处理程序,这是使用jQuery的代码:
$('#yourSelectId').blur();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.