我可以在jQuery“alert”中添加按钮吗?
我可以在jQuery“alert”中添加按钮吗? 我想使用警告框,如确认框。 我需要在警报上有2个按钮,如果用户单击是,则将删除一个人的数据。 如果单击否,则警报将关闭。
使用“JQuery UI”(使用另一个名为JQuery的库在javascript中编写的库),您可以使用以下代码:
$('body').append('Do you wish to Yes or to No
'); $("#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");
alert()
是一个JavaScript函数,与jQuery 无关 。
你可能想要confirm()
提示符 (这也是JavaScript,而不是jQuery)。
var result = confirm("Are you sure you want to delete this user?"); if (result) { // Delete the user } else { // Do nothing; they cancelled }
对于更高级的弹出窗口,您可以使用“模型窗口”模拟自己的弹出窗口; 如果你在互联网上搜索,就会存在很多。