从我的网站搜索其他网站



我想让我的表单在不同的站点中搜索(不同的站点:示例.com)搜索词 (xxx) 需要定向到:http://www.example.com/search___XXX.html

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

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'

最新更新