HTML - 搜索不起作用

时间:2015-10-05 21:57:19

标签: javascript html html5 internet-explorer search

有人可以帮忙吗?

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

如果我按“Enter”或单击搜索按钮,Internet Explorer中就不会发生任何事情。

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

有什么建议吗?谢谢!

print ("\n\n *** Test Normal Cast Variable *** \n\n")

/***
  When a variable is defined and typecast as the struct type, calling a
  computed variable on the variable the setter method of the variable 
  will NOT be called (Desired Behaviour).
***/

var testVar:TestStruct = testProtocolVar as! TestStruct

testVar
testVar.someInt
print("Setter has not been called")
testVar.funcCall()
print("Setter has not been called after function")
testVar.computedVar
print("Setter has not been called when using computed variable")

/*
   *** Test Normal Cast Variable *** 


  Setter has not been called
  Setter has not been called after function
  Setter has not been called when using computed variable
*/

1 个答案:

答案 0 :(得分: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>