简体   繁体   English

取消选择“选择输入”

[英]Unselect a Select Input

I have a "select" input that is programmed to open up a modal box when clicked to get some information before proceeding. 我有一个“选择”输入,编程打开一个模态框,点击以获取一些信息,然后再继续。 That part all works great. 这一部分都很有效。

The problem is that once the modal box is up, the select dropdown options are all still visible. 问题是,一旦模态框启动,选择下拉选项仍然可见。 I want that select input to go back to being a normal, not clicked on at all, select box. 我希望选择输入恢复正常,而不是完全点击,选择框。

What javascript or jquery code can I use to make that select dropdown clear away? 我可以用什么javascript或jquery代码来清除选择下拉列表?

I think it is more correct to move handler from click to change . 我认为将处理程序从click移动到change更为正确。 In this case select will be close and keyboard changes also will be processed 在这种情况下,选择将关闭,键盘更改也将被处理

Try using this instead: 请尝试使用此代码:

$('#mySelect').focus(function(event){
    event.preventDefault();
    // code here
});

If that does't work, try using the preventDefault() with the click event. 如果这不起作用,请尝试使用具有click事件的preventDefault()。 The focus will at least allows users navigating fields with the keyboard (tab, etc) instead of the mouse. 重点将至少允许用户使用键盘(标签等)而不是鼠标来导航字段。

Prior to jQuery 1.6 在jQuery 1.6之前

$('#mySelectBox :selected').attr('selected', '');

jQuery 1.6 and higher jQuery 1.6及更高版本

$('#mySelectBox :selected').removeProp('selected', '');

I'm not sure that you can do it with standard select tag. 我不确定你能用标准选择标签做到这一点。 Maybe because it still has focus. 也许是因为它仍然有焦点。 What I did when I needed a customized select tag is to avoid the select tag completely and use a button which graphically looks like the select button. 当我需要自定义选择标记时,我所做的是完全避免选择标记,并使用一个图形看起来像选择按钮的按钮。 Look at this page - look at the TAX button and the button to the left of it. 看看这个页面 - 看看TAX按钮和它左边的按钮。 There is no select tag, but it works great. 没有选择标签,但效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM