请看我的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;}
当在模态顶部触发甜蜜警报时,输入不会获得焦点。我仍然可以选择顶部的文字,但焦点不会发生。我不确定这是不是来自甜蜜警报。
否则输入正常。
有什么想法吗?
答案 0 :(得分:2)
您可以尝试用空的
覆盖bootstrap的enforceFocus函数$.fn.modal.Constructor.prototype.enforceFocus = function() {};