【问题标题】:Why is Google Chrome emptying my search bar in MediaWiki?为什么 Google Chrome 会清空我在 MediaWiki 中的搜索栏?
【发布时间】:2026-01-22 20:10:01
【问题描述】:

这是一个始于

的传奇

我创建了一个 JavaScript 来根据复选框的选择在 MediaWiki 搜索框中输入文本。这现在适用于 Firefox 和 Internet Explorer。但不在 Google Chrome 中。

在 Chrome 中,搜索框已正确填充(使用上述 JavaScript),但在按下搜索按钮时搜索框为空白(空)。这意味着搜索 URL 也是空白的,这反过来意味着只显示默认的 MediaWiki 搜索页面。

Chrome 对 the code 做了什么,而 FF 和 IE 没有 - 我该如何解决这个问题?

【问题讨论】:

    标签: php javascript google-chrome mediawiki


    【解决方案1】:

    在我的 PHP 代码中,我嵌入了这个 JavaScript:

    <script type="text/javascript">function appendAndSubmit(){var platform1 = document.getElementById('p1').checked;var platform2 = document.getElementById('p2').checked;var text = document.getElementById('searchboxInput').value;if (platform1 * platform2 >0) text = text + ' "Applies to=Platform 1.0" "Applies to=Platform 2.0"';else if (platform1) text = text + ' "Applies to=Platform 1.0"';else if (platform2) text = text + ' "Applies to=Platform 2.0"';document.getElementById('searchboxInput').value = text;document.forms['searchform'].submit();}</script>
    

    变量text 被定义为搜索表单中的内容。所以我只是改变了最后一部分:

    document.forms['searchform'].submit();
    

    text.submit();
    

    它有效,但我不知道为什么。

    【讨论】:

      最近更新 更多