办公室 UI 在搜索框中执行搜索

Office UI Perform Search in SearchBox

我是 Office UI Fabric JS 的新手,我刚刚按照 here 的步骤导入了一个 SearchBox。 但是,当用户按下回车键时,我如何获取查询并执行搜索呢?我在javascript中已经写了一个搜索功能,但我不知道在哪里调用它。 SearchBox 是否有类似 属性 的 onSearch?

此外,<script>...</script> 标签中到底发生了什么?我无法从上面的 link.

中弄清楚以下行的含义

Add the following <script> tag to your page, below the references to Fabric's JS, to instantiate all SearchBox components on the page

好的,这就是我所做的。 首先,您在 HTML 中为 input 字段添加一个 id 元素。

<input class="ms-SearchBox-field" type="text" value="", id="searchText">

然后在我的 JS 文件中,我添加了以下内容:

$('#searchText').on("keypress", function (e) {
    if (e.which == 13) {    // 13 is for enter
        // call search function here
    }
});

我已经在使用 JQuery 所以它很有帮助。