Bad cursor in select/option, IE

后端 未结 2 938
清歌不尽
清歌不尽 2021-01-21 01:43

I have a problem with bad cursor in options when the text is under that.

Normally, the option uses \"default\" cursor, but when eg. the paragraph is under option, in IE

2条回答
  •  被撕碎了的回忆
    2021-01-21 02:36

    IE does not honour the z-index of the select object, and applies the cursor attribute of any underlying object.

    I handle this by changing the cursor attribute of all underlying objects to pointer at the onfocus event for the select object, and restore them at onblur event for the select object.

    It is disappointing that IE does not handle this correctly, as do most other browsers.

    Example code (as requested by DavidG):

    In the this example we apply a class of 'underselect' to all elements that will be covered by the select dropdown (n.b. the dropdown does not always expand downwards, it can expand upwards).

    On page load the initial cursor property of each element with the class 'underselect' is saved in a attribute 'ic' of that element.

    The focus event of the select element is bound to a function that sets the cursor of all elements with the class 'underselect' to pointer.

    The blur event of the select element is bound to a function that sets the cursor of all elements with the class 'underselect' to the initial value that was stored on page load.

    Using jquery

    $(function ()
    {
      $("#select")
        .bind("focus", function(){ $(".underselect").each(function(){$(this).css("cursor", "pointer") });  })
        .bind("blur", function(){ $(".underselect").each(function (i){$(this).css("cursor", $(this).data("ic")); }) });
    
      $(".underselect").each(function () { $(this).data("ic", $(this).css("cursor")); });
    });
    

    Using javascript only we create the following functions:

    function saveinitialcursor()
    {
      gp = document.getElementsByClassName("underselect");
      for (var i = 0, l = gp.length; i < l; i++)
      {
        style = getComputedStyle(gp[i]);
        cursor = style.getPropertyValue("cursor");
        gp[i].setAttribute("ic", cursor);
      }
    }
    
    function selectfocus()
    {
      gp = document.getElementsByClassName("underselect")
      for (var i = 0, l = gp.length; i < l; i++)
        gp[i].style.cursor = "pointer";
    }
    
    function selectblur()
    {
      gp = document.getElementsByClassName("underselect")
      for (var i = 0, l = gp.length; i < l; i++)
        gp[i].style.cursor = gp[i].getAttribute("ic");
    }
    

    and bind them to the body and select opening tags:

    
    
    
                            
        
    提交评论

提交回复
热议问题