我有一个带有搜索按钮的搜索框。当用户在搜索框中输入文本并单击搜索按钮时,应通过将搜索框中输入的文本作为 url 中的参数传递来重定向 url。
#input tag for search box
<input type="search" placeholder="search" class="search_3">
<a href="https:.........?searchname=">
#input tag for search button
<input type="submit" class="submit_3" value="Search"/>
</a>
我必须在 anchor 标记网址中使用输入的文本作为搜索名称参数。
我怎样才能实现这个目标?
最佳答案
我会尝试正确地使用 HTML 标记,以避免无用的 JS。
<form method="GET" action="https:...">
<input type="text" name="searchname"/>
<button type="submit">Go!</button>
</form>
如果 input
位于 form
标记之外,则可以使用 form
属性(请参阅 HTML 生活规范 https://html.spec.whatwg.org/multipage/forms.html#the-input-element )
关于javascript - 从 anchor 标签href url调用js函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39954091/