使用HTML表单创建Google搜索框

时间:2015-05-18 14:14:35

标签: html forms google-search

所以我想在我的网站上插入一个搜索表单,将用户的查询重定向到Google搜索。

我过去常常能够这样做:

<form role="search" method="get" id="searchform" class="searchform" action="http://www.google.co.uk/search?hl=en-GB&source=hp&q=">
  <div id="gform">
    <label class="screen-reader-text" for="s"></label>
    <input type="text" value="" name="s" id="s">
    <input type="submit" class="btn fa-input" value="&#xf002;" style="font-family: FontAwesome;">
  </div>
</form>

然而,这不再适用。我猜测这是因为Google更改了搜索网址,但我无法通过使用Google的当前网址来复制此效果。

知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

大家好,我自己已经解决了这个问题

<div id="gform">
  <label class="screen-reader-text" for="s"></label>
  <input type="text" value="" name="q" id="s">
  <input type="submit" class="btn fa-input" value="&#xf002;" style="font-family: FontAwesome;">	
</div>
解决我的问题的关键是name="q"。这是您进行谷歌搜索工作所需要的;基本上这是因为谷歌希望q作为名称

答案 1 :(得分:1)

此代码段会创建一个简单的Google搜索框

<form action="http://www.google.com/search" method="get">
    <input type="text" name="q"/>
    <input type="submit" value="search" />
</form>