我在我的页面上有以下剃刀:
<a href="@Url.Action("CopyRequestData", "MyRequests", new { area = "Request", id = itm.RequestID })">
<span class="glyphicon glyphicon-copy OptionButton padding-10" id="btnCopyRequest" style="margin-left: 10px;" rowid="@itm.RequestID" data-toggle="popover" data-placement="left" data-content="Create a new request based on this one"></span>
</a>我还有下面的JQuery代码:
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 800, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
//CopyRequest();
return true;
$(this).dialog("close");
},
"No": function () {
return false;
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
rowid = $(this).attr('rowid');
$('#dialog-Copy-request').dialog('open');
});这样,当单击图标按钮时,对话框就会显示出来,但只有在加载新视图的时候才会显示。
该对话框有两个按钮: YES和NO。
我希望新视图仅在单击YES时加载。
我该如何结合图标按钮的a href来做这件事?
发布于 2016-02-19 23:54:26
您可以尝试在单击时模糊href,然后在单击yes时将位置设置为href。
编辑后的html:
<a id="btnCopyRequest" href="@Url.Action("CopyRequestData", "MyRequests", new { area = "Request", id = 1 })">
<span class="glyphicon glyphicon-copy OptionButton padding-10" style="margin-left: 10px;" rowid="1" data-toggle="popover" data-placement="left" data-content="Create a new request based on this one"></span>
</a>已编辑的jQuery
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 800, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
window.location.href = $('#btnCopyRequest').attr('href');
$(this).dialog("close");
},
"No": function () {
return false;
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
event.preventDefault();
rowid = $(this).attr('rowid');
$('#dialog-Copy-request').dialog('open');
});发布于 2016-02-20 03:19:55
在mwwallace8的帮助下,我想出了如何做到这一点。
$('#dialog-Copy-request').dialog({
autoOpen: false, width: 600, resizable: false, modal: true,
title: "Request",
buttons: {
"Yes": function () {
window.location.href = linkObj;
$(this).dialog("close");
},
"No": function () {
$(this).dialog("close");
}
}
});
$(document).on('click', '#btnCopyRequest', function () {
rowid = $(this).attr('rowid');
linkObj = $(this).context.parentNode.href;
$('#dialog-Copy-request').dialog('open');
return false;
});诀窍是将href链接存储在一个全局变量中,并将"return false;“存储在click事件中。然后将window.location.href设置为存储的链接。
https://stackoverflow.com/questions/35509044
复制相似问题