Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在不同站点中从我的站点进行搜索_Javascript_Html_Forms - Fatal编程技术网

Javascript 在不同站点中从我的站点进行搜索

Javascript 在不同站点中从我的站点进行搜索,javascript,html,forms,Javascript,Html,Forms,我想在不同的网站(不同的网站:example.com)上搜索我的表单 搜索词(xxx)需要指向: 一位朋友给我写了这个函数: function SearchKeyword() { var searchKeyword=""; if($('.txtSearch').eq(0).val() !="Search") //mobile searchKeyword = trim( $('.txtSearch').eq(

我想在不同的网站(不同的网站:example.com)上搜索我的表单 搜索词(xxx)需要指向:

一位朋友给我写了这个函数:

function SearchKeyword()
{

var searchKeyword="";

            if($('.txtSearch').eq(0).val() !="Search")   //mobile
                            searchKeyword = trim( $('.txtSearch').eq(0).val() );

            if($('.txtSearch').eq(1).val() !="Search")   
                            searchKeyword = trim( $('.txtSearch').eq(1).val() );                           


 //  searchKeyword = trim($('#txtSearch').val());
if(searchKeyword != ""){        
    document.location.href = 'search___' + searchKeyword + '.html';
}
}
如何将其与此Html表单连接

<div class="wrap">
 <div class="search">
  <input type="text" class="searchTerm" placeholder="What are you looking for?">
  <button type="submit" class="searchButton">
    <i class="fa fa-search"></i>
 </button>

我认为我的朋友没有将代码连接到该站点,而这个JS通常是

谢谢你的帮助!
John

您需要将输入元素的类从
“searchTerm”
更改为
“txtSearch”

或者将函数中的所有
'txtSearch'
更改为
'searchTerm'

尚未工作,需要将函数连接到站点,但如何连接?您所说的“将函数连接到站点”是什么意思?你是说在页面上添加脚本?要添加它,请将函数放在
'
标记之间,就在
'
标记之前。否。我想在不同的网站搜索。(不同网站:example.com)搜索词(xxx)需要指向:脚本上没有