【问题标题】:reload page when item selected in <select> - HTML在 <select> 中选择项目时重新加载页面 - HTML
【发布时间】:2014-11-12 10:09:26
【问题描述】:

我有一个关于使用 &lt;select&gt;&lt;/select&gt; 的小问题

我通过请求从服务器接收数据。对于这个请求,我使用了 shtml。

现在我想要的是,当用户在 de selectbox 中选择一个项目时,页面会从服务器获取该项目的数据。对服务器的请求可能如下所示%! tcp-connections

所以我认为我必须做的是使用 JavaScript 或类似的东西刷新页面。谁能告诉我该怎么做?

【问题讨论】:

    标签: javascript html shtml


    【解决方案1】:

    HTML:

    <select id="select">
        <option selected>Default</option>
        <option value="refresh">Refresh</option>
    </select>
    

    JavaScript:

    function onchange(e) {
        if (e.currentTarget.value === 'refresh') {
            window.location.reload();
        }
    }
    
    document.getElementById('select').addEventListener('change', onchange);
    

    演示:http://jsfiddle.net/w425208t/

    【讨论】:

      【解决方案2】:

      您可以使用以下任何一种:

      window.location.reload(false); 
      // If we needed to pull the document from
      //  the web-server again (such as where the document contents
      //  change dynamically) we would pass the argument as 'true'.
      //i.e. 'true' will force the page to reload from the server. 'false' will reload from cache, if available.
      
      or 
      
      location.reload(); 
      
      or 
      
      window.location.replace(window.location.pathname);
      

      【讨论】:

        【解决方案3】:

        使用window.location.href = yourUrl;它会“重定向”你到带有url yourUrl的页面

        【讨论】:

          猜你喜欢
          • 2021-10-19
          • 1970-01-01
          • 1970-01-01
          • 2020-07-25
          • 2012-06-27
          • 2018-02-28
          • 1970-01-01
          • 2012-06-12
          • 2014-06-06
          相关资源
          最近更新 更多