查询未保留在Internet Explorer中

时间:2013-05-19 00:09:12

标签: javascript html

无法弄清楚为什么在搜索框中进行的查询未在IE中保留(当然)。有人可以打开IE下面的链接

http://www.adhuntr.com/p/results.html?ie=UTF-8&q=ipad+mini&min=&max=&l=all&c=all&t=&p=

2 个答案:

答案 0 :(得分:1)

错误是由addLoadEvent()函数引起的,从IE开发者控制台调用fillSearchBox()只能正确激活此函数并使用查询填充输入框。

特别是,此调用中出现错误:addLoadEvent(fillSearchBox);

我尝试在updated suggestion中使用jsFiddle添加addLoadEvent函数,但没有成功。

由于您在代码中稍微使用了jQuery,因此您可以使用它。 jsFiddle中的示例:

jQuery(document).ready(function () {
   fillSearchBox()
});

顺便说一句,您在input.result上输入了拼写错误,这就是为什么在您选择建议时搜索不会自动提交的原因:

input
    .attr ("autocomplete", "off")
    .autocomplete ("http://clients1.google.com/complete/search", options)
    .result (function () { searchform.submit(); }); //<== typo in this line, should be submit

您真的应该将所有内联代码移动到外部文件,页面中有大量内联JavaScript和CSS,每次页面加载时都需要下载。

答案 1 :(得分:0)

我猜是保留,你的意思是在你输入或建议时出现在搜索栏中?好吧,可能是因为,旧版本的IE即6,7不支持Ajax XMLHttpRequest()对象,因此......你必须更改你的ajax代码,即不到一行,也要检查对于IE的window.ActiveXObject。通过做

if(window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest(); }
        else if(window.ActiveXObject) {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        else {
            alert('Please update your browse, to see Ajax in Action :) ');
    }