如何在表单上添加其他参数,使用GET方法提交

mar*_*zzz 26 html

我有这样的形式:

<form method='GET' name='search' action='index.php?explore=search'> 
    <input type="hidden" name="searchType" value="all" />
    <input class="inputSearchSmall" name="search">
</form>
<a href="javascript:document.search.submit()"><img src="img/button_search.png" class="buttonSearch" /></a>
Run Code Online (Sandbox Code Playgroud)

并且我想在操作链接之后在查询字符串上添加参数.所以,结果必须是:

http://localhost:8080/website/index.php?explore=search&searchType=all&search=example
Run Code Online (Sandbox Code Playgroud)

不是:

http://localhost:8080/website/index.php?searchType=all&search=example
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?添加一个隐藏的参数:

<input type="hidden" name="explore" value="search" />
Run Code Online (Sandbox Code Playgroud)

或者我可以以某种方式将参数连接到动作脚本吗?

Tod*_*odd 22

通过隐藏的参数添加它们就像你建议的那样是最好的方法.它比添加到表单的action属性值更易于维护,并且完全符合您的要求.只需确保将其放在表单标记内.