【问题标题】:Creating a Google search box using HTML form使用 HTML 表单创建 Google 搜索框
【发布时间】:2019-08-28 15:56:02
【问题描述】:

所以我尝试在我的网站上插入一个搜索表单,将用户的查询重定向到 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 更改了搜索 URL,但我无法通过使用 Google 的当前 URL 来复制这种效果。

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

【问题讨论】:

  • 如果粘贴到浏览器中就可以了。你所拥有的不会在一个框架内工作。您是否查看过 F12 错误控制台?提交表单时您会看到什么?
  • 通过将名称更改为 q 来修复
  • @Lukas_T:如果您的问题已经解决,请将其添加为答案。

标签: html forms google-search


【解决方案1】:

大家好,看来我自己解决了问题

<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"。这就是使 google 搜索正常工作所需要的;基本上这是因为 google 期望 q 作为名称

【讨论】:

  • 我会在这里评论说,即使您回答了自己的问题,您仍然应该将其标记为答案,以便未来的观众清楚地看到这是一个有效的答案。
【解决方案2】:

这个 sn-p 创建一个简单的 google 搜索框

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

【讨论】:

    猜你喜欢
    • 2018-02-08
    • 2020-03-12
    • 1970-01-01
    • 2013-06-07
    • 2011-11-28
    • 2012-12-02
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多