2013-04-26 54 views
0

這裏新增了全新的javascript。基於文本輸入的重定向不區分大小寫

我抓住了這一點的代碼,關閉這個網站,我相信,我不記得在哪裏。

<form id='formName' name='formName' onsubmit='redirect();return false;'> 
      <input type='text' id='userInput' name='userInput' value=''> 
      <input type='submit' name='submit' value='Submit'> 
     </form> 

     <script type='text/javascript'> 
     function redirect() { 
      var input = document.getElementById('userInput').value; 
      switch(input) { 
       case 'keyword1': 
        window.location.replace('page1.html'); 
        break; 
       case 'keyword2': 
        window.location.replace('page2.html'); 
        break; 
       default: 
        window.location.replace('error.html'); 
        break; 
      } 


     } 
     </script> 

因爲它是現在它只會工作,如果有人類型「關鍵字1」而不是「關鍵字1」或「KEYWORD1」等等等等,我敢肯定,這是簡單的解決這個問題,但就像我說的,我是新:-p

謝謝。

+2

你嘗試過什麼? – 2013-04-26 15:34:09

+0

你想讓它接受變化嗎? – 2013-04-26 15:35:07

回答

3

交換輸入線:

var input = document.getElementById('userInput').value.toLowerCase(); 
+0

謝謝我知道這是類似的東西,只是不知道它去了哪裏。 – Muskogeee 2013-04-26 15:39:39

1

您可以轉換的字符串做開關之前小寫:

var input = document.getElementById('userInput').value.toLowerCase();