2012-09-28 42 views
-3

我可以將按鈕添加到jQuery「alert」嗎?我想使用提示框,如確認框。我需要在警報上有2個按鈕,如果用戶單擊是,則會刪除一個人的數據。如果點擊否,則警報將關閉。我可以將按鈕添加到jQuery「alert」嗎?

+0

'confirm('Are you sure?');' – Dev

+0

如果我點擊否,數據也會被刪除...... – 0070

+0

查看回答Matt – Dev

回答

0

使用「JQuery用戶界面」您可以使用此代碼(使用名爲JQuery的另一個庫用JavaScript編寫庫):

$('body').append('<div id="yesno_dialog" title="Yes Or No"><p>Do you wish to Yes or to No</p></div>'); 
    $("#yesno_dialog").dialog({ 
     title: "Yes or No", 
     resizable: false, 
     modal: true, 
     buttons: { 
      "Yes" : function() { 
       alert("You chose yes.. now let's do something else here"); 
       $(this).dialog("close"); 
       $(this).remove(); 
      }, 
      "No" : function(){ 
       alert("You chose no.. now let's do something else here"); 
       $(this).dialog("close"); 
       $(this).remove(); 
      } 

     } 
    }); 
} 

但你可能只是需要從確認返回值

return confirm("Are you sure"); 
5

alert()是一個JavaScript函數,並具有什麼做jQuery的。

您可能需要confirm() prompt(也是JavaScript,而不是jQuery)。

var result = confirm("Are you sure you want to delete this user?"); 

if (result) { 
    // Delete the user 
} else { 
    // Do nothing; they cancelled 
} 

對於更高級的彈出窗口,你可以用「模型窗口」模仿自己彈出;如果您在互聯網上搜索,則會存在很多。

+0

現在我點擊確定,取消這兩個按鈕仍然會刪除數據,我想要的是當我點擊確定它會刪除e,當我點擊取消它將關閉彈出窗口並保持在父頁面...我應該在代碼中輸入什麼內容?你能告訴我完整的代碼嗎?我新編程...非常感謝你 – 0070

+0

@ 0070:看到我更新的答案。我不確定您在方案中如何刪除客戶,因此您必須自己編寫代碼,但佔位符在那裏。 – Matt

相關問題