我想制作一个表单,提交后打开一个 html 文件,该文件使用同一选项卡中 URL 末尾的用户提交内容。
例如。提交=link1,打开code.html/link1(同一窗口)
到目前为止,在 window.open("code.html/"+ s... 后面加上 "_self"只会使网址末尾有一个问号,我被告知这是因为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>
最佳答案
也许你可以试试这个:
<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>
关于javascript - 创建一个提交表单,使用其输入来确定链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41093095/