我正在使用 Sharepoint online 2015。在创建列表项期间,我需要保存列表项并将页面重定向到创建的列表项的 EditForm.aspx 而不是 AllItems.aspx。
按钮的html代码如下:
<button type="button" id="idSaveProceed">Save & Proceed</button>
以下是保存列表项并将其重定向到编辑表单的 jQuery 代码:
$("#idSaveProceed").click(function(event){
event.preventDefault();
if (!PreSaveItem()) return false;
if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2')) return false;
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", "", false, true));
GetListItemId(); // This will redirect the page to EditFoem.aspx;
});
但是当代码 if (SPClientForms.ClientFormManager.SubmitClientForm('WPQ2'))
执行时,页面重定向发生在 AllItems.aspx 上。我什至在 WebForm_DoPostBackWithOptions
中提供了自定义 url。但在执行该代码之前,页面会被重定向。
我试过使用 event.preventdefault()
但没有用。
请让我知道这里缺少什么。提前致谢。
注意:我不想使用 InfoPath。我只想要一个 jQuery 解决方案来处理这个问题。
最佳答案
你还需要更新
< form id="aspnetForm" action="< url >?Source=...">
源参数
查看此网址。 http://formsdesigner.blogspot.in/2013/04/redirect-after-sharepoint-form.html
但很好奇您将如何获得新提交的项目 ID?
关于javascript - 表单提交后无法阻止页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195672/