Show dropdown in jQuery?

Possible duplicate:
How can you programmatically report that you have selected HTML SELECT (for example, because of a mouse)?

Is it possible to set the select dropdown visible with jQuery?

I tried to use $('#dropdown').click();, but it has no effect.

+3
source share
3 answers

It's impossible. You can implement your own select-box, but this is bad for usability.

another approach is to programmatically change the size attribute in the select box, but this is not quite what you wanted.

I suggest thinking about why you need it, and if there is a better software template?

+5

:

HTML

<button id='btn'>Click Me</button>
<select id='test'>
    <option>Blah 1</option>
    <option>Blah 2</option>
    <option>Blah 3</option>
    <option>Blah 4</option>
</select>

JavaScript

$('#btn').click(function(){
    $('#test').attr('size', 5);
});

$('#test').change(function() {
   $(this).attr('size', 1); 
});

, .

.

+3

- . , - "" , . focus, .

, CSS. , , , , - , .

, . , size 1, . , :

$("#open").click(function(e){
   e.preventDefault();
   $("#myselect").attr("size",5);    
});

$("#myselect").click(function(){
   $(this).attr("size",1); 
});

http://jsfiddle.net/jonathon/cr25U/

+2

Source: https://habr.com/ru/post/1780587/


All Articles