如何修复 jQuery 对话框 UI 的 zIndex 问题

Jay*_*len 2 z-index jquery-plugins jquery-dialog

我的对话框用户界面有一个小问题。我将 zIndex 值标记为高数字,但它似乎忽略了它。

以下是我的代码

        $( "#number-add" ).dialog({
            resizable: false,
            width: 500,
            modal: false,
            autoOpen: false,
            stack: false,
            zIndex: 9999,
            buttons: {
            "Add Contact": function(e) {

            var formData = $('#number-add-form').serialize();

            //submit record
            $.ajax({    
                type: 'POST',
                url: 'ajax/handler-add-new-account-number.php',     
                data: formData,
                dataType: 'json',
                cache: false,
                timeout: 7000,
                success: function(data) {           

                    $('#responceAddNumber').removeClass().addClass((data.error === true) ? 'errorBox' : 'passBox').html(data.msg).fadeIn('fast');   

                    if ($('#responceAddNumber').hasClass('passBox')) {
                        $('#responceAddNumber').fadeIn('fast');
                        $('#add-form').hide();              

                        window.location.reload();
                        setTimeout(function() {

                            $(this).dialog( "close" );                          
                        }, 1000);


                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {

                    $('#response-add').removeClass().addClass('errorBox')
                                .html('<p>There was an<strong> ' + errorThrown +
                                      '</strong> error due to a<strong> ' + textStatus +
                                      '</strong> condition.</p>').fadeIn('fast');           
                },              
                complete: function(XMLHttpRequest, status) {            
                    if (   $('#response-add').hasClass('passBox') ){
                        $('form')[0].reset();
                    }
                }
            }); 



            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }

        }
    });
Run Code Online (Sandbox Code Playgroud)

我将堆栈值设置为 false,将 zIndex 设置为 9999。我在这里做错了什么,导致 zIndex 不起作用?我正在使用 jQuery UI 对话框 1.10.2。

感谢您的帮助。

Bla*_*ell 6

我在 jQuery UI 1.9 中花了太长时间来解决这个问题。最终我决定采用这种有点暴力的方法来为我的模式对话框设置 z-index。

$('#dialog').dialog({
    modal: true,
    zIndex: 25,
    stack: false,
    open: function (event, ui) {
        $('#dialog').parent('.ui-dialog').css('zIndex', 26)
            .nextAll('.ui-widget-overlay').css('zIndex', 25);
    }
});
Run Code Online (Sandbox Code Playgroud)

您可能需要在 open 事件中使用 DOM 遍历来正确选择覆盖,或者如果您不使用模式对话框则忽略它,但这给了我良好可靠的结果。