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

时间:2016-01-28 16:45:58

标签: php html forms refresh

我有form

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

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

我怎样才能做到这一点?

感谢阅读!

1 个答案:

答案 0 :(得分:1)

<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>

有关详情,请查看on change()&amp; Change URL

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