1

我正在尝试使用一些 JavaScript 打开 SharePoint 模态对话框以提示用户输入,然后将该值存储到变量中。有谁知道如何做到这一点?我正在为 Nintex 任务表单执行此操作。

4

1 回答 1

3

你试过什么了?最简单的选择是利用 SP.UI.ModalDialog 类,该类提供打开本机 SP 模式的方法 - 您可以通过 URL 参数加载单独的页面(ASPX、HTML 等)或将 HTML 直接传递给模式呈现。

使用任何一种方法,您的标记都可以包含一个<input>从用户那里捕获值和随附的 JS 以将输入值存储在您想要的任何位置(包括在变量中)。

根据您使用的其他 JS(如果有)或页面的设置方式,您可能还需要利用 SP2013 的“按需脚本”(SOD)功能来确保加载 SP 模态所需的 JS。

这是一个简单的例子:

function OpenMyModal(SomeVar) {
    // If using inline HTML, first create a parent element...
    var MyHtmlElement = document.createElement('div');
    // ... then populate it
    MyHtmlElement.innerHTML = '<input... />';

    // Define the Modal's options
    var options = {
        // define a URL (and yes, you can pass params to that URL) or reference your HTML object, but NOT both!
        url: '../MyPage.aspx?MyParam=' + SomeVar + '&IsDlg=1',
        // html: MyHtmlElement,
        tite: 'Modal Title',
        allowMaximize: false,
        showClose: true,
        width: 430,
        height: 230
    };
    // This ensures the supporting JS needed is loaded on the page
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
    return false;
}
于 2016-10-08T21:19:51.017 回答