如何使用 XHTML/HTML 为网站添加站点搜索功能?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3016287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:25:06  来源:igfitidea点击:

How to add site search function to website using XHTML/HTML?

htmlxhtml

提问by felixd68

I really want to learn how to make my own search engine for my site. I have the defined buttons and labels, but it doesn't search. I can't figure out the HTML or XHTML code for actually searching the site.

我真的很想学习如何为我的网站制作自己的搜索引擎。我有定义的按钮和标签,但它不搜索。我无法弄清楚用于实际搜索站点的 HTML 或 XHTML 代码。

This is the code I have so far:

这是我到目前为止的代码:

<p class="search">
    <label>SEARCH</label>
    <input name="search" type="text" class="txt" />
    <input name="search-btn" type="submit" class="btn" value="SEARCH" />
</p>

Thanks!

谢谢!

回答by Michael Madsen

You cannot provide a search function with just HTML and XHTML, unless you're just using a standardized form to get some external search engine (like Google) to do the work.

您不能仅使用 HTML 和 XHTML 来提供搜索功能,除非您只是使用标准化的表单来让某些外部搜索引擎(如 Google)来完成这项工作。

It is possible to do search with JavaScript, but that requires you to transfer all the data to the client, so it is not a very good idea.

可以使用 JavaScript 进行搜索,但这需要您将所有数据传输到客户端,因此这不是一个好主意。

If you want to write it yourself, you should use some server-side language, such as PHP or Python - it depends on what you have access to.

如果你想自己编写它,你应该使用一些服务器端语言,比如 PHP 或 Python - 这取决于你可以访问什么。

回答by Jim Lamb

回答by ewall

There is no feature in HTML that will perform the search. But you do have 3 alternative options:

HTML 中没有执行搜索的功能。但是您确实有 3 个替代选项:

  1. You can integrate 3rd-party search engines like Google into your site. (Or see one of these examples.)
  2. You can upload a CGI page which uses PHP, Perl, or another scripting language to perform the local search for you.
  3. Lastly, there are some options for JavaScript search engines which work right inside the page.
  1. 您可以将 Google 等第 3 方搜索引擎集成到您的网站中。(或查看这些示例之一。)
  2. 您可以上传一个CGI 页面,该页面使用 PHP、Perl 或其他脚本语言为您执行本地搜索。
  3. 最后,JavaScript 搜索引擎有一些选项可以直接在页面内工作

回答by Mike Comstock

Adding search to your site isn't nearly as simple as creating a search form: it also involves a bunch of programming. Depending on your experience level and what you are trying to do, it can be fun and rewarding to program simple search functionality to your site, but it can also be extremely time-consuming. If you want to take the easy route, use http://www.google.com/sitesearch/as Jim suggested. If you want to make it yourself, see something like How would I implement a simple site search with php and mySQL?to get started.

向您的站点添加搜索几乎不像创建搜索表单那么简单:它还涉及大量编程。根据您的经验水平和您尝试做的事情,为您的网站编写简单的搜索功能可能会很有趣且有益,但也可能非常耗时。如果您想走简单的路线,按照 Jim 的建议使用http://www.google.com/sitesearch/。如果您想自己制作,请参阅如何使用 php 和 mySQL 实现简单的站点搜索?开始。