2013-07-29 22 views
2

我的網頁刪除表中的一行並將其自動保存在數據庫中。點擊刪除按鈕後,我需要一個messageBox,兩個按鈕「保存」和「否」。在JSP 刪除功能低於:添加「保存」或「否」的提醒框

function deleteFileRow(rowCount) 
{ 
$.ajax(
    { 
     url: 'deleteRow.htm?rowIndex='+rowCount+"&action=delete&id="+${id}, 
     success: function(data) 
     { 
      document.location.reload(); 
     } 
    }); 
} 

請幫我做這個。

+0

你爲什麼不去[jquery alert](http://jqueryui.com/dialog/)? – NINCOMPOOP

+2

或者你可以使用簡單的確認框:http://stackoverflow.com/questions/4292455/javascript-confirm-dialog – Cherniv

+0

但我相信'確認'框中的標籤可能無法定製! – NINCOMPOOP

回答

1

here你可以找到如何彈出一個消息框是/否,並在JavaScript ,你可以使用,如果你不能確定「保存」 /「不」

var nRslt = app.alert ("Press \"yes\" to save\n" + "Press \"No\" to delete";, 2, 2, "Submit Validation"); 
if(nRslt == 4) { // User Pressed Yes, Do submission 
    this.submitForm(...); 
} 
4

使用jQuery的問題確認框添加是或否。

ConfirmDialog('Are you sure'); 

function ConfirmDialog(message){ 
$('<div></div>').appendTo('body') 
       .html('<div><h6>'+message+'?</h6></div>') 
       .dialog({ 
        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true, 
        width: 'auto', resizable: false, 
        buttons: { 
         Yes: function() { 
          // $(obj).removeAttr('onclick');         
          // $(obj).parents('.Parent').remove(); 

          $(this).dialog("close"); 
         }, 
         No: function() { 
          $(this).dialog("close"); 
         } 
        }, 
        close: function (event, ui) { 
         $(this).remove(); 
        } 
       }); 
}; 

裁判http://jsfiddle.net/nM3Zc/

1

問題是解決了用下面的代碼:

function deleteFileRow(rowCount){ 
var stay=confirm("Are you sure, You want to delete Row? Click "ok" to confirm, "cancel" Otherwise") 
if(stay) 
{ 
     $.ajax({ 
     url: 'deleteRow.htm?rowIndex='+rowCount+"&action=delete&testid="+${testid}, 
     success: function(data) { 
      document.location.reload(); 
     } 
     }); 
} 
} 

Ajax調用將裏面的 「確認」。