我有一个完美工作的切换按钮。javascript和视图如下:
jQuery:
$('.list-delist-link').delegate("a", "click", function (e) {
var obj = $(this);
if ($(this).hasClass('delist-property')) {
// Post to controller
e.preventDefault();
} else {
// Post to controller
e.preventDefault();
}
});
看法:
<div class="list-delist-link">
@if(item.IsPropertyDisabled) {
@Html.ActionLink("List", "Enable", "Property", new { id = item.PropertyId }, new { @class="list-property other-button" })
} else {
@Html.ActionLink("Delist", "Disable", "Property", new { id = item.PropertyId }, new { @class="delist-property other-button" })
}
</div>
但是,现在我想在 ajax 操作之前添加一个确认对话框。但是,当我尝试这样做时,一切都崩溃了……我不知道为什么。我在布局页面上有 jQuery 和 css 文件
我所做的更改如下:
jQuery 的变化:
var obj;
$('.list-delist-link').delegate("a", "click", function (e) {
obj = $(this);
$("#dialog-confirm").dialog(open):
e.preventDefault();
});
用于模态确认的附加 jQuery:
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false, height:140, modal: true,
buttons: {
"Delete all items": function() {
if (obj.hasClass('delist-property')) {
// Post to controller
} else {
// Post to controller
}
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
});
视图中的附加 div:
<div id="dialog-confirm" title="Are you sure?">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
你能告诉我有什么问题吗?