【问题标题】:Search field not working in Chrome搜索字段在 Chrome 中不起作用
【发布时间】:2012-01-12 16:08:08
【问题描述】:

我的网站上有一个搜索文本字段,在 Chrome 或 FireFox 中似乎无法正常运行...但在 IE(所有版本)中运行...

我做错了什么吗?我无法找到为什么没有将值传递给“搜索器”应用程序。

<div class="searchbox" id="searchbox"> 
    <script type="text/ecmascript"> 
        function RunSearch() { 
            window.location = "http://searcher.myexampledomain.com:8765/query.html?ql=&amp;col=web1&amp;qt=" + document.getElementById("search").value; 
        } 
    </script> 
        <div class="formSrchr"> 
            <input type="text" size="20" name="qt" id="search" value="Search" onfocus="if(this.value == 'Search') {this.value=''}" onblur="if(this.value == ''){this.value ='Search'}" />
            <input type="hidden" name="qlOld" id="qlOld" value="" /> 
            <input type="hidden" name="colOld" id="colOld" value="web1" /> 
            <input type="image" name="imageField" alt="search" src="/_images/search-mag.gif" onclick="RunSearch();" /> 
        </div> 
</div> <!-- /searchbox -->

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    您不应该对 URL 中的 &amp; 进行 HTML 编码。

    这就够了;

    window.location.href = "http://searcher.myexampledomain.com:8765/query.html?ql=&amp;col=web1&amp;qt=" + document.getElementById("search").value;

    【讨论】:

    • OP 还应该考虑使用window.location.href 而不是window.location,正如以下问题中所指出的:stackoverflow.com/questions/2345807/…
    • 它是 & 符号...谢谢您.. 将这两个实例更改为未编码的符号,现在可以使用了。我可以跟进这个问题...??为什么当我刚刚点击“输入”按钮时,它不会再次提交,对于 Chrome 或 FF,但在 IE 中可以使用???
    • 您的表单不包含任何submit 按钮。 &lt;input type="submit" value="Submit the form" /&gt;.
    • 您可以将函数调用从input onclick 属性移动到forms onsubmit 并在form 中添加一个隐藏的提交按钮。隐藏的提交按钮见stackoverflow.com/questions/29943/…
    • 我不能也用图片提交吗?
    【解决方案2】:
    <script type="text/ecmascript"> 
    

    可能是问题所在,并导致浏览器之间的反应不同。尝试更改它:

    <script type="text/javascript"> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多