HTML - 搜索栏在Internet Explorer中不起作用

时间:2015-10-01 22:52:21

标签: javascript html internet-explorer search uisearchbar

有人可以帮忙吗?

我创建了此搜索栏,该搜索栏适用于Google Chrome,但不适用于Internet Explorer。

如果我按"输入"或者单击搜索按钮在Internet Explorer中没有任何反应。

我应该被重定向到一个页面,就像chrome中发生的一样。

有什么建议吗?谢谢!

<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 个答案:

答案 0 :(得分:0)

&#13;
&#13;
<html>
<body>

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

<form>
  <input type="search" list="colors" id="searchbox" placeholder="What Color?" name="color_repeat" required autocomplete="off"
   onsearch="location.href = 'https://www.google.com/search?q='+document.getElementById('searchbox').value;">
  <input type="button" value="Search" onclick="location.href = 'https://www.google.com/search?q='+document.getElementById('searchbox').value;">  
</form>

</body>
</html>
&#13;
&#13;
&#13;

这适用于Internet Explorer 11和Google Chrome,可以获取您的价值并将您重定向到相应的Google搜索。但是,您遇到的问题是Internet Explorer中的onsearch事件为not supported。这可以通过使用按钮的onclick事件来规避,即supported。我希望这对您的问题有所帮助!