[英]html form without submit button and anchor link onclick redirect with input value
我想這樣重定向用戶: example.com/search/[search+text]
html源代碼:
<form name="menu_search" method="get" onsubmit="window.location.href = 'http://www.col3negmovie.com/search/'+this.q.value+''; return false;" >
<input name="q" id="videoSearch" />
</form>
這是錨鏈接:
<a href="./#" onclick="document.menu_search.submit(); window.location.href='http://www.col3negmovie.com/search/'+this.q.value+''; return false;">Search</a>
onclick不起作用,我該如何解決?
onclick="document.menu_search.submit();
window.location.href='http://www.col3negmovie.com/search/'+this.q.value+'';
return false;"
您的表格:
<form name="menu_search" method="get" onsubmit="window.location.href = 'http://www.col3negmovie.com/search/'+document.getElementsByName('q')[0].value+''; return false;" >
<input name="q" id="videoSearch" />
</form>
錨標簽:
<a href="./#" onclick="document.getElementsByName('menu_search')[0].submit(); return false;">Search</a>
或沒有<form>
標記(這使得它不那么混亂):
<input name="q" id="videoSearch" />
<a href="./#" onclick="window.location.href = 'http://www.col3negmovie.com/search/' + document.getElementById('videoSearch').value;">Search</a>
要在按下“ Enter”鍵時執行相同的操作:
document.getElementById("videoSearch").onkeyup = function() {
if (this.event.keyCode == 13 || this.event.which == 13)
//Enter was pressed, handle it here
window.location.href = 'http://www.col3negmovie.com/search/' + document.getElementById('videoSearch').value;
}
}
希望能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.