首页 > 解决方案 > 如何使用 javascript html 填充具有多个路径的下拉列表

问题描述

我正在处理 Excel Web 加载项项目,我需要与多个共享文件夹路径建立连接。当用户在下拉列表中选择路径时,它会自动获取数据并在 Excel 表中打开它。我在 Visual Studio 中使用 JavaScript 和 HTML。

所以这是我的 HTML 代码:

<td><label class="ms-Label is-required ms-font-l">Path : </label></td>
<td>
    <select class="ms-Dropdown-item--selected is-required" id="path">
        <option href="\\myservername.com\Fin1\ ">Server 1</option>
        <option href="\\myservername.com\Fin2\ ">Server 2</option>
        <option href="\\myservername.com\Fin3\ ">Server 3</option>
</select>
 </td>

<script>
   document.getElementById('path').onchange = function (ctx) {
       window.location.href = this.children[this.selectedIndex].getAttribute('href');
   } </script>

每个选项都与不同的服务器路径连接。我尝试使用window.location.href但是当我选择服务器路径时,输出替换了我的表单。我希望它在 Excel 工作表上显示输出而不是替换我的表单。

标签: javascripthtml

解决方案


推荐阅读