Javascript 制作一个使用其输入确定链接的提交表单

Javascript 制作一个使用其输入确定链接的提交表单,javascript,html,forms,input,Javascript,Html,Forms,Input,我想制作一个表单,在提交时打开一个html文件,在同一选项卡的url末尾使用用户提交 例如,Submit=link1,打开code.html/link1(同一窗口) 到目前为止,在window.open(“code.html/”+s…)后面加上“\u self”只会使url在末尾有一个问号,我听说这是因为GET方法 (Javascript) <script> var s = document.getElementById("submit").value; function doFun

我想制作一个表单,在提交时打开一个html文件,在同一选项卡的url末尾使用用户提交

例如,Submit=link1,打开code.html/link1(同一窗口)

到目前为止,在window.open(“code.html/”+s…)后面加上“\u self”只会使url在末尾有一个问号,我听说这是因为GET方法

(Javascript)
<script>
var s = document.getElementById("submit").value;
function doFunction(){window.open("code.html/" + s);}
</script>

(HTML)
<form onsubmit="doFunction()">
  <input id="submit" type="text" />
</form>
(Javascript)
var s=document.getElementById(“提交”).value;
函数doFunction(){window.open(“code.html/”+s);}
(HTML)

也许您可以尝试以下方法:

<form onSubmit="return doFunction();" target="_self">
 <input id="text-value" type="text" >
 <input type ="submit">
</form>
<script type="text/javascript">
   function doFunction(){
   var s = document.getElementById("text-value").value;
   var url = "code.html/" + s;
   var win = window.open(url, '_self');
   return false;
}
</script>