[英]HTML - search does not work
任何人都可以帮忙吗?
我创建了这个搜索栏,它可以在 google chrome 中使用,但不能在 Internet Explorer 中使用。
如果我按“Enter”或单击搜索按钮,则 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>
也许在表单中添加一个动作会有所帮助。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.