我想用jQuery對話框覆蓋javascript確認。這裏是我的overridin代碼:
用jquery覆蓋javascript確認
window.confirm = function(message, caption = 'Confirmation'){
$(document.createElement('div')).attr({title: caption, 'class': 'dialog'}).html(message).dialog({
position:['center',100],
dialogClass: 'fixed',
buttons: {
"OK": function(){
$(this).dialog('close');
return true;
},
"Cancel": function(){
$(this).dialog('close');
return false;
}
},
close: function(){
$(this).remove();
},
draggable: false,
modal: true,
resizable: false,
width: 'auto'
});
};
這裏是我的動作代碼:
if(confirm('Are you sure?') == false) { return false; }
此代碼不能正常工作。我怎樣才能做到這一點?
你的意思是什麼不起作用?它是否在控制檯上拋出一些js錯誤? – dreamweiver
對於它的工作,函數'confirm()'只有在彈出被解除後才能返回*。從彈出式按鈕事件處理程序中返回true/false不會將其剪切。 – techfoobar
它不會按預期工作,因爲該對話框異步執行...在你的情況下,確認沒有返回任何東西(未定義)..解決方案是使用回調方法 –