我可以在jQuery“警报"中添加按钮吗? [英] Can I add buttons to jQuery "alert"?
本文介绍了我可以在jQuery“警报"中添加按钮吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以向jQuery警报"中添加按钮吗?我想使用像确认框一样的警告框.我需要在警报上有2个按钮,如果用户单击是",则将删除一个人的数据.如果单击否,则警报将关闭.
Can I add buttons to jQuery "alert"? I want to use the alert box like the confirmation box. I need to have 2 button on the alert, if user click yes, the data of a person will be delete. If click no, then the alert will be close.
推荐答案
使用"JQuery UI"(使用另一个名为JQuery的库以javascript编写的库),您可以使用以下代码:
Using "JQuery UI" (a library written in javascript using another library named JQuery) you can use this code:
$('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();
}
}
});
}
但是您可能只需要从确认中返回值即可
But you probably just need to return the value from confirm
return confirm("Are you sure");
这篇关于我可以在jQuery“警报"中添加按钮吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文