JQuery on focus event with html select tag

I use jquery to change the background of the dropdown. For some reason, it now takes two clicks to select an item rather than a single click.

What I cannot find out is why this is happening, and an effective workaround or even better fix. It seems like this is happening in ie7 and ie 8 (if a friend tested it on his box) Below is the exact code that we use to test this problem.

----------------------------- FULL MARKUP ---------------- --- -------------

  

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

<style type="text/css">
    .yellowBackground, .yellowBackground > * > *
    {
        background-color: #FFFF79;
    }
</style>

<script type="text/javascript">

    $(document).ready(function() {
        $('select').focus(function() {

            $(this).addClass('yellowBackground');

        })
    });
</script>
</head>
<body>
    <form>
    <select>
        <option value="A">Option 1</option>
        <option value="B">Option 2</option>
    </select>
    </form>
</body>
</html>
+5
source share
2 answers

This is apparently a known issue in IE7 and forwarding .

, onmousedown .

    $(document).ready(function() {
        $('select').mousedown(function() {

            $(this).addClass('yellowBackground');

        })
    });

, onfocusin ( jquery).

+2

, , <asp:DropDownList>. , . aspx ?

0

All Articles