简体   繁体   English

在 URL 搜索中传递参数

[英]Passing Parameter in URL search

I am in the process of creating a search functionality.我正在创建搜索功能。 Please see UI example .请参阅UI 示例 The following is my HTML以下是我的 HTML

  <form class="navbar-form" role="search">
      <div class="form-group">
        <input type="text" class="form-control" placeholder="Search">
      </div>
    <button type="submit" class="btn"><span class="glyphicon glyphicon-search"></span> Search</button>
    <a class="btn" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    <span class="glyphicon glyphicon-menu-hamburger"></span> Filter
  </a>
  </form>

When the search button is clicked, whatever term has been entered needs to be passed in URL via a JS script in order to go to another page and display results.单击搜索按钮时,无论输入什么词,都需要通过 JS 脚本在 URL 中传递,以便转到另一个页面并显示结果。

Any help would be appreciated任何帮助,将不胜感激

Thank you谢谢

Add the action and method attributes to the form tag.actionmethod属性添加到form标记。 And the name attribute to the input tag.以及input标签的name属性。

This will go to the URL: search.php?term=value这将转到 URL: search.php?term=value

<form action="search.php" method="GET" class="navbar-form" role="search">
    <div class="form-group">
        <input type="text" name="term" class="form-control" placeholder="Search">
    </div>
    <button type="submit" class="btn btn-anz"><span class="glyphicon glyphicon-search"></span> Search</button>
    <a class="btn btn-anz" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
        <span class="glyphicon glyphicon-menu-hamburger"></span> Filter
    </a>
</form>

Yo have to add method and action attributes to the from tag.你必须向 from 标签添加方法和动作属性。

Like this-像这样-

<form action="search.php" method="GET" class="navbar-form" role="search">
<div class="form-group">
    <input type="text" name="item" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-anz"><span class="glyphicon glyphicon-search"></span> Search</button>
<a class="btn btn-anz" role="button" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
    <span class="glyphicon glyphicon-menu-hamburger"></span> Filter
</a>

then using javascriupt you can use appropriate techinique to retrieve the value and process the search results.然后使用 javascriupt 您可以使用适当的技术来检索值并处理搜索结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM