gpt4 book ai didi

javascript - MVC jquery 对话框无法正常工作

转载 作者:行者123 更新时间:2023-12-01 05:45:06 26 4
gpt4 key购买 nike

当我单击删除按钮时,弹出对话框显示然后消失。它不会停留

这是代码:

.cshtml:

@Html.ActionLink("Delete", "DeleteOrder", "Order", new { id = item.OrderID }, new { @class = "btn btn-primary btn-delete"} );


<div id="dialog-confirm" title="Confirmation Dialog" style="display:none">Delete this Order? Confirm </div>

<script>
$(document).ready(function () {

$(".btn-delete").click(function () {
var result;

$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Yes": function () {
$(this).dialog("close");
},
"No": function () {
$(this).dialog("close");
return false;
}
}
});

});
});
</script>

最佳答案

处理 anchor 点击并打开对话框,如果是,则将浏览器 URL 设置为 anchor href 属性

$(".btn-delete").click(function(e) {
var ahref = $(this)
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
buttons: {
"Yes": function() {
$(this).dialog("close");

window.location = $(ahref).prop("href");
},
"No": function() {
$(this).dialog("close");
}
}
});

e.preventDefault();
});
<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

<a href="http://example.com" class="btn-delete">delete item</a>
<div id="dialog-confirm"></div>

关于javascript - MVC jquery 对话框无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27501945/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com