如何创建在多个标签页中打开多个搜索结果,从不同的搜索引擎搜索框? [英] How to create a search box that open multiple search results from different search engines in multiple tabs?

查看:137
本文介绍了如何创建在多个标签页中打开多个搜索结果,从不同的搜索引擎搜索框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个搜索框和一个提交按钮,将在多个标签从多个搜索引擎的搜索结果中打开我的输入。谢谢你。

解决方案

你描述你想要做的,不需要你使用Ajax做些什么的方式

Ajax是用于从网络加载数据和该用户是上,使用Ajax可以不移动到一个新的页面更新页面的页面的更新部分。

既然你问到打开新的标签页,Ajax已经无关了。

 < HTML>
< HEAD>
<脚本类型=文/ JavaScript的>
传播performSearch(){
    VAR搜索关键词= EN codeURIComponent(的document.getElementById('searchField')值。);
    的window.open('http://www.google.com/search?q=+搜索关键词,'new_window_1');
    的window.open('http://search.yahoo.com/search?p=+搜索关键词,'new_window_2');
    //这里打开更多标签...
}
< / SCRIPT>
< /头>

<身体GT;
<输入ID =searchField类型=文本/>
<输入类型=按钮值=点击我的onclick =performSearch(); />
< /身体GT;
< / HTML>
 


  

你能告诉我如何使搜索文本框后执行pressing搜索输入?

快捷方式:

如果我们让我们的文本字段中实际的HTML表单的一部分,使我们的JavaScript函数运行,当用户提交表单 - 这将导致函数运行,当用户点击文本字段中输入,因为点击进入在文本框,是表单的一部分提交表单。

 < HTML>
< HEAD>
<脚本类型=文/ JavaScript的>
传播performSearch(){
    VAR搜索关键词= EN codeURIComponent(的document.getElementById('searchField')值。);
    的window.open('http://www.google.com/search?q=+搜索关键词,'new_window_1');
    的window.open('http://search.yahoo.com/search?p=+搜索关键词,'new_window_2');
    //这里打开更多标签...
}
< / SCRIPT>
< /头>

<身体GT;
<形成的onsubmit =performSearch();返回false;>
<输入ID =searchField类型=文本/>
<输入类型=提交值=点击我/>
< /形式GT;
< /身体GT;
< / HTML>
 

现在的按钮输入的类型是'提交',所以当用户点击按钮的形式应该得到提交的,而我们在窗体上的事件处理程序 - 在onsubmit的 - 这运行时,用户点击按钮或presses搜索领域进入里面。我们加入'返回false;'所以,没有什么实际发生的我们的函数运行后 - 的形式实际上没有得到提交(因为当你提交一个表单,你通常发送信息的地方,我们不这样做,在这里,它就像一个伪形式)。

I need a search box and a submit button that will open my input in multiple tabs as the search result from multiple search engines. Thanks.

解决方案

The way you described what you want to do does not require you to use Ajax.

Ajax is for loading data from the web and updating parts of the page that the user is on, with Ajax you can update the page without moving to a new page.

Since you asked to open new tabs, Ajax has nothing to do with it.

<html>
<head>
<script type="text/javascript">
function performSearch() {
    var searchTerm = encodeURIComponent(document.getElementById('searchField').value);
    window.open('http://www.google.com/search?q=' + searchTerm, 'new_window_1');
    window.open('http://search.yahoo.com/search?p=' + searchTerm, 'new_window_2');
    // open more tabs here ...
}
</script>
</head>

<body>
<input id="searchField" type="text" />
<input type="button" value="click me" onclick="performSearch();" />
</body>
</html>


Can you tell me how to make the search field to perform search after pressing enter?

The quick way:

if we make our text field a part of an actual HTML form, and make our javascript function run when the user submits the form - that will cause the function to run when the user clicks enter inside the text field, because clicking enter inside a text box that is part of a form submits the form.

<html>
<head>
<script type="text/javascript">
function performSearch() {
    var searchTerm = encodeURIComponent(document.getElementById('searchField').value);
    window.open('http://www.google.com/search?q=' + searchTerm, 'new_window_1');
    window.open('http://search.yahoo.com/search?p=' + searchTerm, 'new_window_2');
    // open more tabs here ...
}
</script>
</head>

<body>
<form onsubmit="performSearch(); return false;">
<input id="searchField" type="text" />
<input type="submit" value="click me" />
</form>
</body>
</html>

Now the type of the button input is 'submit', so when the user clicks the button the form should get submitted, and we have an event handler on the form - the 'onsubmit' - this runs when the user clicks the button or presses enter inside the search field. We add 'return false;' so that nothing actually happens after our function runs - the form doesn't actually get submitted (because when you submit a form you usually send information somewhere, we don't do that here, it's like a pseudo-form).

这篇关于如何创建在多个标签页中打开多个搜索结果,从不同的搜索引擎搜索框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆