2015-10-05 152 views
2

任何人都可以幫忙嗎?HTML - 搜索不起作用

我創建的谷歌瀏覽器的工作原理,但無法在Internet Explorer這個搜索欄。

如果我按「Enter」鍵或點擊搜索按鈕什麼也沒有發生在Internet Explorer中。

我應該被重定向到一個網頁,如鉻,會發生什麼。

有什麼建議嗎?謝謝!

<html> 
     <body> 

    <datalist id="colors"> 
     <option value="Red"> 
     <option value="Blue "> 
     <option value="Green"> 
     <option value="Black"> 
     </datalist> 


    <input type="hidden" id="color" name="color" value="RED" required> 
    <input type="hidden" id="color2" name="color2" value="BLUE" required> 
    <input type="hidden" id="color3" name="color3" value="GREEN" required> 
    <input type="hidden" id="color4" name="color4" value="BLACK" required> 

    <form> 
     <input type="search" list="colors" class="searchbox" id="searchbox" placeholder="What Color?" name="color_repeat" required autocomplete="off" 
     onsearch="check(this)"> 
     <input type="button" class="button" id="button" value="Search" onclick="check(document.getElementById('searchbox'))"> 
    </form> 

    <script> 
    function check(input) 

    { 
    if (input.value.toUpperCase() != document.getElementById('color').value) 
    { 
    if (input.value.toUpperCase() != document.getElementById('color2').value) 
    { 
    if (input.value.toUpperCase() != document.getElementById('color3').value) 
    { 
    if (input.value.toUpperCase() != document.getElementById('color4').value) 
    {  

    } 
    else 
    { 
    window.top.location.href = 'http://www.color.com.br/BLACK’ 
    } 
    } 
    else 
    { 
    window.top.location.href = 'http://www.color.com.br/GREEN’ 
    } 
    } 
    else 
    { 
    window.top.location.href = 'http://www.color.com.br/BLUE’ 
    } 
    } 
    else 
    { 
    window.top.location.href = 'http://www.color.com.br/BLUE’ 
    } 

    } 
    </script> 


</body> 
</html> 

回答

1

也許在窗體中添加一個動作將有所幫助。

<form action="javascript:check(document.getElementById('searchbox'))"> 
    <input type="search" list="colors" class="searchbox" id="searchbox" placeholder="What Color?" name="color_repeat" required autocomplete="off" 
    onsearch="check(this)"> 
    <input type="submit" class="button" id="button" value="Search"> 
</form> 

我建議通過移動的getElementById到函數編輯功能:

<form action="javascript:check()"> 
    <input type="search" list="colors" class="searchbox" id="searchbox" placeholder="What Color?" name="color_repeat" required autocomplete="off" onsearch="check(this)"> 
    <input type="submit" class="button" id="button" value="Search"> 
</form> 
<script> 
    function check() { 
     var input = document.getElementById('searchbox'); 
     if (input.value.toUpperCase() != document.getElementById('color').value) { 
      if (input.value.toUpperCase() != document.getElementById('color2').value) { 
       if (input.value.toUpperCase() != document.getElementById('color3').value) { 
        if (input.value.toUpperCase() != document.getElementById('color4').value) { 
        } else { 
         window.top.location.href = 'http://www.color.com.br/BLACK’ 
        } 
       } else { 
        window.top.location.href = 'http://www.color.com.br/GREEN’ 
       } 
      } else { 
       window.top.location.href = 'http://www.color.com.br/BLUE’ 
      } 
     } else { 
      window.top.location.href = 'http://www.color.com.br/BLUE’ 
     } 

    } 
</script> 
+0

這位朋友你好感謝了很多,但還是失敗了。在Internet Explorer中,該頁面的鏈接出現在地址欄中,但該頁面未顯示。 –