如何强制表单仅通过 Google 搜索在特定网站内进行搜索

JAT*_*T86 3 html forms google-search

我有一个简单的搜索表单,我希望在单击按钮时将其重定向到 Google 搜索页面以搜索输入。下面的代码有效:

<form role='search' method='get' action='http://www.google.com/search'>
  <input type='search' name='q' />
  <button type='search' value='search'>Search</button>
</form>
Run Code Online (Sandbox Code Playgroud)

但是,我只想搜索特定网站。我尝试修改 name='q'下面的代码以仅在 w3schools 内搜索(添加site:w3schools.com),但特定于站点的搜索不起作用:

<input type='search' name='q=site%3Aw3schools.com' />
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

小智 6

<form action="http://www.google.com/search" method="get">
   <input type="hidden" name="q" value="site:http://yoursite.com">
   <input type="text" name="q" alt="search">
   <input type="submit" value="Search">
</form>
Run Code Online (Sandbox Code Playgroud)