Javascript 为什么我不去那个网址?

Javascript 为什么我不去那个网址?,javascript,html,url,web,Javascript,Html,Url,Web,我正在制作一个类似谷歌的搜索引擎,我刚刚开始制作。 但是有个问题!当我键入GoogleTranslate时,它不会转到我用JavaScript为它编写代码的时候,即:“window.location.href=;” 现在看我的代码,这是我的search.js: function search_Results (form) { var search_term = form.search_box.value; //This is the search term //About out c

我正在制作一个类似谷歌的搜索引擎,我刚刚开始制作。 但是有个问题!当我键入GoogleTranslate时,它不会转到我用JavaScript为它编写代码的时候,即:“window.location.href=;”

现在看我的代码,这是我的search.js:

function search_Results (form) {

  var search_term = form.search_box.value; //This is the search term

  //About out company
  if(search_term == "About" ||
     search_term == "about")
     {
         alert("About");
     }

  //Google translate
  else if(search_term == "Google translate" ||
          search_term == "google translate"// ||
          //search_term == "Google Translate" ||
         // search_term == "google Translate"
          )
          {
              location.href='http://www.example.com';
          }
  else
  {
      alert("Extremely sorry! Your search term: '"+search_term+"' does not matches any search documents.");
  }
}
这是我的searchengine.html:

<!DOCTYPE html>
<html>
<head>
 <!----The search script---->
 <script src="Search/search.js"></script>
 <!----The style scripts---->
 <link rel="stylesheet" type="text/css" href="GUI/button.css">
 <link rel="stylesheet" type="text/css" href="GUI/heading.css">
 <link rel="stylesheet" type="text/css" href="GUI/txtinput.css">
</head>
<body>
 <center>
 <!----Heading---->
 <h1 class="heading">Search Engine</h1>
 <!----End that---->
 <!----Search options---->
 <a href="searchImages.html"> 
  <button class="btn">Images</button>
 </a>
 <a href="searchVideos.html">
  <button class="btn">Videos</button>
 </a>
 <!----End of the search options---->
 <!----The main search form---->
 <form name="wow" method="">
  <br><br><br>
  <input type="text" name="search_box" value="Enter Your Search Term" class="css-input">
  <br><br>
  <input type="submit" value="Search" onClick="search_Results(this.form)" class="btn">
 </form>
 <div id="div1">
 </div>
 <!----End of the search form---->
 </center>
</body>
</html>
但是这些都没有帮助我。

试着用type=button代替type=submit。它会工作,因为它不会提交表单,而提交就是这样做的

<input type="button" value="Search" onClick="search_Results(this.form)" class="btn">
尝试使用type=button代替type=submit。它会工作,因为它不会提交表单,而提交就是这样做的

<input type="button" value="Search" onClick="search_Results(this.form)" class="btn">
我建议您使用switch而不是创建ifelseif丛林。我建议您使用switch而不是创建ifelseif丛林。