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

时间:2014-04-11 09:15:25

标签: javascript html forms

我想重定向这样的人: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;"

1 个答案:

答案 0 :(得分:2)

您的表格:

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

在输入&#39;时执行相同的操作。被迫:

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

希望有所帮助。