Jquery date picker z-index issue

前端 未结 14 2067
傲寒
傲寒 2020-12-02 12:57

I have a slideshow div, and I have a datepicker field above that div.

When I click in the datepicker field, the datepicker panel show behind slideshow div.

相关标签:
14条回答
  • 2020-12-02 13:19

    I have a dialog box that uses the datepicker on it. It was always hidden. When I adjusted the z-index, the field on the lower form always showed up on the dialog.

    I used a combination of solutions that I saw to resolve the issue.

    $('.ui-datepicker', $form).datepicker({
                    showButtonPanel: true,
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: "yy-M-dd",
                    beforeShow: function (input) {
                        $(input).css({
                            "position": "relative",
                            "z-index": 999999
                        });
                    },
                    onClose: function () { $('.ui-datepicker').css({ 'z-index': 0  } ); }                    
                });
    

    The before show ensures that datepicker always is on top when selected, but the onClose ensures that the z-index of the field gets reset so that it doesn't overlap on any dialogs opened later with a different datepicker.

    0 讨论(0)
  • 2020-12-02 13:20

    I have a page where the datepicker was on top of a datatables.net tabletools button. The datatables buttons had a higher z-index than the individual datepicker date buttons. Thanks to Ronye's answer I was able to resolve this problem by using position: relative; and z-index: 10000. Thanks!

    0 讨论(0)
  • 2020-12-02 13:21

    See here: http://forum.jquery.com/topic/z-index-1-datepicker-1-8

    0 讨论(0)
  • 2020-12-02 13:22

    worked for me

    .hasDatepicker {
        position: relative;
        z-index: 9999;
    }
    
    0 讨论(0)
  • 2020-12-02 13:28

    Based in marksyzm answer, this worked for me:

    $('input').datepicker({
        beforeShow:function(input) {
            $(input).css({
                "position": "relative",
                "z-index": 999999
            });
        }
    });
    
    0 讨论(0)
  • 2020-12-02 13:31

    Adding to Justin's answer, if you're worried about untidy markup or you don't want this value hard coded in CSS you can set the input before it is shown. Something like this:

    $('input').datepicker({
        beforeShow:function(input){
            $(input).dialog("widget").css({
                "position": "relative",
                "z-index": 20
            });
        }
    });
    

    Note that you cannot omit the "position": "relative" rule, as the plugin either looks in the inline style for both rules or the stylesheet, but not both.

    The dialog("widget") is the actual datepicker that pops up.

    0 讨论(0)
提交回复
热议问题