简体   繁体   English

没有提交按钮和锚点链接的html表单onclick使用输入值重定向

[英]html form without submit button and anchor link onclick redirect with input value

I want to redirect people like this: example.com/search/[search+text] 我想这样重定向用户: example.com/search/[search+text]

html source code: 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>

this is the anchor link : 这是锚链接:

<a href="./#" onclick="document.menu_search.submit(); window.location.href='http://www.col3negmovie.com/search/'+this.q.value+''; return false;">Search</a>

onclick doesn't work, how could i fix this? onclick不起作用,我该如何解决?

onclick="document.menu_search.submit();
window.location.href='http://www.col3negmovie.com/search/'+this.q.value+'';
return false;"

Your form: 您的表格:

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

Anchor tag: 锚标签:

<a href="./#" onclick="document.getElementsByName('menu_search')[0].submit(); return false;">Search</a>



Or without the <form> tag (which makes it less confusing): 或没有<form>标记(这使得它不那么混乱):

<input name="q" id="videoSearch" />
<a href="./#" onclick="window.location.href = 'http://www.col3negmovie.com/search/' + document.getElementById('videoSearch').value;">Search</a>

To do the same when 'Enter' is pressed: 要在按下“ 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;
}
}

Hope that helped. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM