javascript 如何制作简单的搜索引擎?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12554308/
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-10-26 16:30:04  来源:igfitidea点击:

How to make simple search engine?

javascript

提问by Bikash Jit

guys please help me to create one simple search engine it should be like when user write any word and hit the enter button my webpage will not show him a list of results but its opposite it should open that particular page, a web page that I'll put somehow in the code and define that- if this keyword is entered open this page. E.g., if user type's A in the search box and click search then it should open page "/a.html" A is a first letter of alphabets.

伙计们,请帮我创建一个简单的搜索引擎,就像当用户输入任何单词并按下回车键时,我的网页不会向他显示结果列表,但相反,它应该打开那个特定页面,一个我打开的网页我会以某种方式放入代码并定义 - 如果输入此关键字,则打开此页面。例如,如果用户在搜索框中键入 A 并单击搜索,那么它应该打开页面“/a.html” A 是字母的第一个字母。

Just like How http://dictionary.reference.comdoes (Its Dictionary site) So what it does is when user types a word of which he/she wants the meanings then dictionary.reference.com dont show a list of result, It shows the meaning directly. Just like that. Is that can be done with html form and javascript.? If yes how ?

就像http://dictionary.reference.com 的作用一样(它的字典网站) 所以它的作用是当用户输入一个他/她想要含义的单词时,dictionary.reference.com 不显示结果列表,它直接说明意思。就这样。可以用 html 表单和 javascript 来完成吗?如果是怎么办?

回答by Joyce Babu

Did you mean this? http://jsfiddle.net/Sz2bC/2/

你是这个意思吗? http://jsfiddle.net/Sz2bC/2/

<script>
function redirect() {
    document.location.href = '/browse/' + document.getElementById('search').value;
    return false;
}
</script>

<form onsubmit="return redirect();">
<input id="search" type="text" />
<input type="submit" value="Search">
</form>