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

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

本文关键字:onclick 链接 重定向 输入 表单 提交 按钮 html      更新时间:2023-09-26

我想像这样重定向人员: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;
}
}

希望能有所帮助。