gpt4 book ai didi

javascript - 没有提交按钮和 anchor 链接 onclick 重定向并输入值的 html 表单

转载 作者:行者123 更新时间:2023-12-02 17:31:42 25 4
gpt4 key购买 nike

我想像这样重定向用户: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>

这是 anchor 链接:

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

anchor 标记:

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

希望有所帮助。

关于javascript - 没有提交按钮和 anchor 链接 onclick 重定向并输入值的 html 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23008359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com