2012-05-25 93 views
0

如何在從數據庫中刪除條目之前添加問題警報窗口(類似於「刪除第2行?」)?在從數據庫刪除行之前添加警報窗口

<script type="text/javascript"> 
function deleteRow(tableName,colName,id, obj){ 
    $.ajax({ 
      type: "POST", 
      url: "callpage.php?page=tables/delete.php", 
      data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id, 
      success: function(msg){ 
      if(msg === '1'){ 
       obj = $(obj).parents('tr'); 
       $(obj).slideUp().remove(); 
      } 
      else 
       alert("Error."); 
      } 
    }); 
} 
</script> 

回答

0

您需要使用JavaScript confirm box爲puprose會做你的任務

function deleteRow(tableName,colName,id, obj){ 
    var r=confirm("you need to delete row from" + tableName + "having id :" +id); 
    if (r==true) 
     { 
      $.ajax({ 
        type: "POST", 
        url: "callpage.php?page=tables/delete.php", 
        data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id, 
        success: function(msg){ 
        if(msg === '1'){ 
         obj = $(obj).parents('tr'); 
         $(obj).slideUp().remove(); 
        } 
        else 
         alert("Error."); 
        } 
      }); 

     } 
    else 
     { 
     alert("You pressed Cancel!"); 
     } 
} 
+0

** JavaSCRIPT ** !! –

+0

謝謝,它的工作原理。但是如果我想使用jQuery警報消息樣式呢? –

+0

@Treffynnon:在1999-2000年初,我學習了W3schools之後的早期Web開發。原因很簡單,清楚,明白。沒有知道他們發佈誤導性或不準確的內容,直到2012年,當我看到上述w3fools ..網站:-) lolz – verisimilitude

0

您可以使用確認窗口中出現了類似的代碼

if (confirm('Want to delete row XY ? ')) { 
    $.ajax({ 
      type: "POST", 
      url: "callpage.php?page=tables/delete.php", 
      data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id, 
      success: function(msg){ 
      if(msg === '1'){ 
       obj = $(obj).parents('tr'); 
       $(obj).slideUp().remove(); 
      } 
      else 
       alert("Error."); 
      } 
    }); 
} 
0

您應該添加確認在您致電前彈出:

function deleteRow(tableName, colName, id, obj) { 
    if(confirm("Are you sure to delete this row?")) { 
    // ... 
    } 
} 
2

您可以使用JavaScript的window.confirm()函數來顯示一個確認對話框給用戶,並根據他們的選擇更加簡單if聲明,要麼是OKtrue)或取消false):

<script type="text/javascript"> 
function deleteRow(tableName,colName,id, obj){ 
    if(window.confirm('Delete row ' + id + '?')){ 
     $.ajax({ 
       type: "POST", 
       url: "callpage.php?page=tables/delete.php", 
       data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id, 
       success: function(msg){ 
       if(msg === '1'){ 
        obj = $(obj).parents('tr'); 
        $(obj).slideUp().remove(); 
       } 
       else 
        alert("Error."); 
       } 
     }); 
    } 
} 
</script> 
0

在ajax調用之前放置一個html confirm()。

var r=confirm("Do you want to delete?") 
if (r==true) 
{ 
    //call the delete function 
} 
0

簡單和確認框的一個非常基本的解釋。

var r=confirm("Press a button"); 
if (r==true) 
{ 
    alert("You pressed OK!"); 
} 
else 
{ 
    alert("You pressed Cancel!"); 
} 

相關問題