gpt4 book ai didi

javascript - HTML - 搜索不起作用

转载 作者:行者123 更新时间:2023-11-28 01:23:32 25 4
gpt4 key购买 nike

有人能帮忙吗?

我创建的这个搜索栏在 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>

最佳答案

也许向表单添加一个 Action 会有所帮助。

<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>

关于javascript - HTML - 搜索不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32958580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com