我的页面上有以下剃须刀:
<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时加载新视图。
如何与图标按钮的href结合使用?
答案 0 :(得分:1)
您可以尝试在点击时模糊href,然后在点击是时将位置设置为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');
});
答案 1 :(得分:0)
在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链接存储在全局变量中,并且&#34;返回false;&#34;在点击事件中。然后将window.location.href设置为存储的链接。