2016-01-28 136 views
0

轉至該網址我有一個formHTML表單:從輸入字段

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

的形式被插入值後公佈。現在我不只是想刷新網站,但重定向到/whatIwroteintotheInputfield.

我該如何實現這一目標?

感謝您的閱讀!

回答

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() & Change URL

而且,從我身邊的一個問題。爲什麼你需要<form></form>。它也可以在沒有<form>的情況下完成。所以,如果可能的話(如果不需要的話),然後刪除<form></form>

+0

謝謝你!我已經在使用jQuery,所以看起來這是最好的解決方案。感謝您的回答! :) – Skalibran

+0

*很高興幫助*':D:)'@Skalibran –