如何在点击引导弹出按钮时读取响应?
问题描述:
我正在开发MVC应用程序。我正在使用CSS的bootstrp。如何在点击引导弹出按钮时读取响应?
我想在删除记录使用警报/对话框进行确认。 它应该要求确定/取消,并根据按钮单击下一个过程将被执行...
我已经从下面的代码形式一些论坛,它工作正常,但没有得到任何事件,如果我点击在确定或取消按钮
如何从阅读下面的代码这些点击的事件?
$('#Deactivate').click(function() {
var href = $(this).attr('href');
if (!$('#dataConfirmModal').length) {
$('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h6 id="dataConfirmLabel">Deactivation Confirmation</h6></div><div class="modal-body"><h3>Are you sure to deactive @Model.Name ?</h3> </div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button><a class="btn btn-primary" id="dataConfirmOK">OK</a></div></div>');
}
$('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
$('#dataConfirmOK').attr('href', href);
$('#dataConfirmModal').modal({show:true});
$('#dataConfirmOK').on('click', function(e)
{
alert('@Model.Id');
var url2 = "@Html.Raw(Url.Action("DeactivateParty", "Party", new { @id = "PoNo"}))";
alert(url2);
url2 = url2.replace("PoNo", '@Model.Id');
$.post(url2, function (data) {
if(data == true)
{
var url = $("#RedirectTo").val();
location.href = url ;
}
});
return false;
});
答
您必须指定的事件处理程序的OK按钮:
$('#dataConfirmOK').on('click', function(e) {
// Call your delete action here
});
答
看起来你有封闭语法错误POST方法:
$.post(url2, function (data) {
if(data == true)
{
var url = $("#RedirectTo").val();
location.href = url;
}
应该的。 ...
$.post(url2, function (data) {
if(data == true)
{
var url = $("#RedirectTo").val();
location.href = url ;
}
})
nb如果你转储您发布的代码放入您喜爱的浏览器的控制台窗口中,您将看到该错误。
+0
非常感谢...它的工作原理...语法错误在那里... – bnil 2013-05-03 08:25:53
+0
@ user1650894如果人们试图提供更多。 – 2013-05-05 10:13:43
感谢扬,我已经更新了我的问题。当我不在** dataConfirmOK **中放置任何代码时,它完美的工作,但我把任何代码放在OK按钮上,然后它不工作...请检查我更新的问题... – bnil 2013-05-03 07:42:40
@ user1650894:你的意思是什么*它不工作* – Jan 2013-05-03 07:44:59
按钮事件内部的代码不工作...我已经把'alert('@ Model.Id');'来检查光标是否进入该功能,但它不会来...是否我写了什么错误的代码? – bnil 2013-05-03 07:49:55