我在 mvc3 中使用提交按钮执行删除操作。 我想显示一个确认框 当我单击按钮时,我使用了下面的 jquery。该查询用于静态数据,但 我想使用我的数据库。当我点击提交按钮时,消息出现但是 即使我单击确定,它也会显示错误消息。我应该怎么做才能让它发挥作用。
<script type="text/javascript">
$(document).ready(function () {
$("#button").click(function (event) {
event.preventDefault();
var link = this;
if (confirm("Are you sure that you want to delete this user?")) {
$.ajax({
type: "POST",
url: link.href,
success: function (data)
{
$(link).parents("tr").remove();
alert("deleted");
},
error: function (data)
{
event.preventDefault();
alert(" Unsuccessful");
}
});
}
}
);
});
最佳答案
试试这个:
<asp:Button ID="btn" runat="server" Text="Click"
OnClientClick="return confirmDialog(this);"
onclick="btn_Click" />
var confirmed = false;
function confirmDialog(obj)
{
if(!confirmed)
{
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Yes": function()
{
$( this ).dialog( "close" );
confirmed = true; obj.click();
},
"No": function()
{
$( this ).dialog( "close" );
}
}
});
}
return confirmed;
}
http://markmintoff.com/2011/03/asp-net-jquery-confirm-dialog/
关于c# - 如何使用数据库在mvc3中的jquery中显示确认框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11342428/