HTML 表单:从输入字段转到 URL


HTML Forms: Go to the url from the input field

我有一个form

<form method="post" action="/whatIwroteintotheInputfield">
  <input type="text" onchange="this.form.submit();"></input>
</form>

插入值后将发布表单。现在我不仅想刷新网站,还想重定向到/whatIwroteintotheInputfield.

我怎样才能做到这一点?

感谢您的阅读!

<form method="post" action="yourTextURL">
    <input type="text" id="changeText" value="http://"></input>
</form>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
    $("#changeText").on('change', function() {
          var url = $('#changeText').val();
          window.location = url;
    });
</script>

有关更多信息,请查看 change() & Change URL

而且,我这边有一个问题。那你为什么需要<form></form>。也可以在没有<form>的情况下完成。因此,如果可能(如果不需要),请删除<form></form>.