【发布时间】:2014-11-25 00:47:29
【问题描述】:
当用户点击DELETE按钮时,我想显示一个确认对话框菜单。
但按钮不会触发我的脚本。触发 JavaScript 后,如果用户选择 OK,则脚本必须执行该操作。否则,如果用户单击取消,则不会发生任何事情。
这是 JavaScript 代码;
<script type="text/javascript">
$(document).ready(function () {
$(".confirmDialog").on("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 170,
width: 350,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location = url;
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
return false;
});
});
</script>
这里是MVC代码;
<div style="text-align: right; font-weight: bold; font-size: larger; color: red;">
<tr>
<td>@Html.ActionLink("Delete", "Your-Action", new { @class = "confirmDialog" })</td>
</tr>
</div>
<div id="dialog-confirm" style="display: none">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Are you sure ?
</p>
</div>
【问题讨论】:
-
确保您的链接 html 看起来像您预期的那样
标签: javascript jquery asp.net asp.net-mvc asp.net-mvc-4