JQuery/[removed] IE hover doesn't cover select box options?

后端 未结 5 1441
半阙折子戏
半阙折子戏 2020-12-11 22:36

I have this bit of script to widen a text box on mouseover and shorten it on mouseoff.

The problem I am having is that Internet Explorer doesn\'t seem to extend it\'

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 23:03

    Apparently IE doesn't consider the drop down bit part of the select element. It's doable, but it takes a bit of cheating with expando properties and blur/focus events to enable and disable the 'hide' effect to stop it kicking in when the mouse enters the drop-down part of the element.

    Have a go with this:

    $(function() {
        var expand   = function(){ $(this).width(600) }
        var contract = function(){ if (!this.noHide) $(this).width(50) }
        var focus    = function(){ this.noHide = true }
        var blur     = function(){ this.noHide = false; contract.call(this) }
        $('#TheSelect')
            .hover(expand, contract)
            .focus(focus)
            .click(focus)
            .blur(blur)
            .change(blur)
    });
    

    (Apologies if this isn't how one is supposed to use jQuery - I've never used it before :))

提交回复
热议问题