0
我有一个简单的形式是这样的:HTML链接,追加查询字符串到当前URL
<form>
<input name="search">
<button type="submit">Search...</button>
Price: <a href="?filter=price&direction=asc">Low</a> |
<a href="?filter=price&direction=desc">High</a>
</form>
注意input
与search
名称可以搜索一个关键字,而<a>
链接作为过滤器工作。当您提交表单时,网址将会是localhost/products?search=smartphone
。通过我的服务器端脚本,这将生成一个页面,其中包含名称中包含单词smartphone
的所有产品。
现在说我在localhost?search=smartphone
。如果我点击Low
,它会产生
http://localhost/products?filter=price&direction=asc
-> filter all products with price asc
不过,我真的很打算得到的是
http://localhost/products?search=smartphone&filter=price&direction=asc
-> search for 'smartphone', and filter only those results by price asc
我要如何才能到达search
和filter
结合(其asc
或desc
方向) ?在旁注中,这在搜索/过滤方面是否有效?我应该将<a>
更改为<input>
?我几乎没有搜索机制的经验,所以任何建议,将不胜感激!
这是行不通的。它要么给我'http:// localhost/products?search = some_value'或'http:// localhost/products?filter = name&direction = asc'。它需要有'过滤器'和'搜索' – Alex
更新我的答案。现在检查。 –