2

请看我的 jsfiddle https://jsfiddle.net/fp2vg48z/2/

这是代码:

$('a').click(function(){
    $( "#container" ).dialog({
        height: 430,
        width: 620,
        title: 'click hello',
        modal: true,
        buttons: [
            {
                text: 'Back',
                click: function() {
                    $( this ).dialog( "close" );
                }
            }
        ],
        create: function( event, ui ) {

        },
        close: function( event, ui ) {

        }
    });
});

$('.justalert').click(function(){
        swal({
            title: 'hello',
            text:'Please enter name',
            type:'input',
            showCancelButton: true,
            closeOnConfirm: false,
            inputPlaceholder: "E.g john" 
        }, function(inputValue){   
            if (inputValue === false) 
                return false;      
            if (inputValue === "") {     
                swal.showInputError("You need to enter something!");     
                return false;  
            }                               
        swal({title: " success " + inputValue+" added!", type:"success", timer:10000 });
    });
});

$(document).on('click','.hello',function(){
    swal({
        title: 'hello',
        text:'Please enter name',
        type:'input',
        showCancelButton: true,
        closeOnConfirm: false,
        inputPlaceholder: "E.g john" 
    }, function(inputValue){   
        if (inputValue === false) 
            return false;      
        if (inputValue === "") {     
            swal.showInputError("You need to enter something!");     
            return false;  
        }                               
        swal({title: " success " + inputValue+" added!", type:"success", timer:10000 });

    });
});

CSS:

#container{ padding:20px; background:#ccc;display:none;}
.sweet-overlay{z-index:5000;}
.sweet-alert{z-index:5001;}

当在模式顶部触发甜蜜警报时,输入不会获得焦点。我仍然可以选择顶部的文本,但焦点没有发生。我不确定这是否来自甜蜜警报。

否则输入工作正常。

有任何想法吗?

4

1 回答 1

3

你可以尝试用一个空的覆盖引导程序的enforceFocus函数

$.fn.modal.Constructor.prototype.enforceFocus = function() {};
于 2016-11-16T14:24:47.407 回答