您应该在这里使用回调,因为如果您停用 javascript,用户将无法单击“确定”
window.alert = function(message, callback){
var dialog = $('<div>'+message+'</div>').dialog({
title:'Alert',
buttons:{
'Ok': function(){
$(this).dialog('close').data('open', false);
$(this).remove();
typeof callback=='function' && callback(); //check if callback, and execute it
}
}
}).data('open', true);
}
alert('test',function(){console.log('The user has clicked on the ok');});
编辑:
如果您只想暂停alert执行而不是其他代码执行,您可以执行以下操作(我没有尝试过,但想法就在这里):
var alertStack=[];
window.alert = function(message){
if(!message || !alertStack.length)
$('<div>'+(alertStack[0] || message)+'</div>').dialog({
title:'Alert',
buttons:{
'Ok': function(){
alertStack.shift()
$(this).dialog('close').data('open', false);
$(this).remove();
alertStack.length && alert();
}
}
}).data('open', true);
message && alertStack.push(message);
}
alert('test');
alert('test2');
alert('test3');