基于选择的输入,单击按钮后重定向到新的html页面

时间:2019-05-29 08:38:31

标签: javascript html

我是javascript新手。根据从下拉列表中选择的输入,单击下一步后,我需要重定向到新的html页面。

...
<p>Application Type&nbsp
<select id = "aList" name="selection">
<option value = "">---Select Value---</option>
<option value = "New_req_p2_web.html">External Web Application</option>
<option value = "New_req_p2_web.html">Internal Web Application</option>
<option value = "New_req_p2_mob.html">Mobile Application</option>
<option value = "New_req_p2_net.html">Network</option>
</select>
</p>
<button type="submit" id="next" onclick="WinOpen()">Next</button>
....
<script type="text/javascript">
function WinOpen() {
var url=document.redirect.selection.value
document.location.href=url
}
</script>
...

2 个答案:

答案 0 :(得分:2)

这里更新的代码,希望对您有用。

谢谢

<p>Application Type&nbsp
<select id="aList" name="selection">
  <option value="">---Select Value---</option>
  <option value="New_req_p2_web.html">External Web Application</option>
  <option value="New_req_p2_web.html">Internal Web Application</option>
  <option value="New_req_p2_mob.html">Mobile Application</option>
  <option value="New_req_p2_net.html">Network</option>
</select>
</p>
<button type="submit" id="next" onClick="WinOpen();">Next</button>

<script type="text/javascript">
  function WinOpen() {
    var url = document.getElementById("aList").value;
    document.location.href = url;
  }
</script>

答案 1 :(得分:0)

您可以执行以下操作:

您需要根据您当前所在的页面来确保该html页面的路径/值正确,因此这些值可能需要更改为类似./New_req_p2_web.html

<p>Application Type</p>
<select id="aList" name="selection">
<option value="">---Select Value---</option>
<option value="New_req_p2_web.html">External Web Application</option>
<option value="New_req_p2_web.html">Internal Web Application</option>
<option value="New_req_p2_mob.html">Mobile Application</option>
<option value="New_req_p2_net.html">Network</option>
</select>
<button type="submit" id="next" onclick="WinOpen()">Next</button>

<script type="text/javascript">
//THIS WILL OPEN IN A NEW WINDOW/TAB
function WinOpen() {
    var url = $('#aList').val();
    window.open(url);
}
//THIS WILL OPEN ON ITS SELF - if you use this remove the onclick for the button. 
$('#next').click(function () {
     var url = $('#aList').val();
     window.open(url, "_self");
});

</script>

您的路径需要正确的值,我的意思是,如果此文件位于您的桌面文件夹中,则您的“ New_req_p2_web.html”必须位于同一文件夹中,除非您更改路径值。