我的搜索栏无法在其他浏览器中使用

时间:2018-07-28 23:30:29

标签: javascript html

我的网站上有一个工作正常的搜索栏,但它仅适用于谷歌浏览器... ?有人可以帮助我吗?我真的很糊涂。我真的需要它在所有浏览器中都可以使用,而不仅仅是google chrome。 这是搜索栏的代码...

'<div class="search_box">
    <form action="" id="form2">
        <div>
            <input type="text" id="search" input name="q" type="text" placeholder="What are you looking for?" value="" autocomplete="off" maxlength="240" class="f-input js-search-field ">
            <input type="button" id="submit_form" onclick="checkInput()" value="Search"
/span>
        </div>
    </form>
</div>


<script>
    function checkInput() {
        var query = document.getElementById('search').value;
        window.find(query);
        return true;
    }
</script>'

请不仅在谷歌浏览器上使用所有浏览器。谢谢!

1 个答案:

答案 0 :(得分:0)

您的疑问归结为使用单个功能:window.find

这是mozilla中关于该函数的确切示例,更多的是您尝试执行的操作:

findString = function findText(text) {
  alert("String " + text + " found? " + window.find(text));
}
<p>Apples, Bananas, and Oranges.</p>
<button type="button" onClick='findString("Apples")'>Search for Apples</button>
<button type="button" onClick='findString("Banana")'>Search for Banana</button>
<button type="button" onClick='findString("Orange")'>Search for Orange</button>

Mozilla页面警告该功能的使用:

  

此功能不是标准功能,也不在标准轨道上。请勿在面向Web的生产站点上使用它:它不适用于每个用户。实现之间也可能存在很大的不兼容性,并且将来的行为可能会发生变化。

Here is another post讨论了要使此跨浏览器兼容时应阅读的替代方法。

相关问题