开发者

Why won't this select open up?

开发者 https://www.devze.com 2023-01-20 17:21 出处:网络
I have a very simple select drop down. In Chrome, it doesn\'t drop down. The code itself wor开发者_运维知识库ks fine, and the drop down works in Safari, but for some reason it won\'t open in Chrome. H

I have a very simple select drop down. In Chrome, it doesn't drop down. The code itself wor开发者_运维知识库ks fine, and the drop down works in Safari, but for some reason it won't open in Chrome. Here is the HTML:

<select name="pellet_credit" class="item_discount">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

It should be pretty simple. It's a dropdown... Here's a screenshot of the select, selected, but not open:

Why won't this select open up?

--- edit ---

This is a jsfiddle with the full source included. The dropdown works for me in the jsfiddle view, but not on the actual site.

http://jsfiddle.net/HSYvf/

--- edit ---

Other drop downs on the page work fine.


Validate your HTML to make sure there aren't extraneous closing/end tags. Make sure you aren't hiding the options through CSS as well.


I had the same problem with Firefox and Chrome and due to the z-index of the form being -1.

When changed the z-index, it worked fine.


This happened to me when I put a <select> inside a jQuery .sortable() element. I copied this code right off the jQuery website, and the .disableSelection() method call killed my <select>.

$(function() {
    $( "#sortable" ).sortable();
    $( "#sortable" ).disableSelection();
});

Once I removed the .disableSelection(); (which oddly enough they've deprecated...) everything worked just fine.


I think you should set a value for your options

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

you can read more here


what ended up happening to me that caused me to be on this page is that display was set to display:none; on the option elements

solution:

$(yourdropdown).children().show();


We had a crazy problem when we were developing a client/server programming language which had a listbox. Although INPUT worked the listbox didn't. We have mouse tracking on it and by a bug the $(window).mousedown... was being enabled by default.

We were able to track the problem with this page: https://hackernoon.com/finding-that-pesky-listener-thats-hijacking-your-event-javascript-b590593f2a83

Just in case the above page disappears:

In Chrome (possibly other Chromium flavours [works on Opera too]):

  1. Right click on element.
  2. Click 'Inspect...'
  3. When the 'Elements' are shown, the right panel will have [Styles][Computed][Event Listeners] (tabs). Click on 'Event Listeners'.
  4. Look for 'mouseup', 'mousedown', 'keyup', etc and expand what you suspect and remove it to see if that fixes the problem (debug).
  5. Change the code.

What we did was change the 'return false' to 'return true' in our code.


To debug such issues try removing all attributes from the html and add them one at a time to find out what is causing the issue. For example, the snippet below does not work as needed.

<select size="10">
  <option value=1>1</option>
  <option value=2>2</option>
  <option value=3>3</option>
</select>

Removing the size attribute fixes it

<select >
  <option value=1>1</option>
  <option value=2>2</option>
  <option value=3>3</option>
</select>


I'm adding an answer just to call out the comment by @Agos in the selected answer. Check if you have event handling code (mousedown, click, etc.) that might be stealing the events from the dropdown.


The problem for me was that I had included class names in the id declaration.

For future audience, notice in particular if your select element is inconsistent with the surrounding form styles. This is a likely clue that a class isn't being applied correctly, and you may have accidentally placed it in the wrong spot.

0

精彩评论

暂无评论...
验证码 换一张
取 消