Jquery date picker z-index issue

前端 未结 14 2147
傲寒
傲寒 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.

提交回复
热议问题