document.form.action无法在IE中运行,但在Chrome和Firefox中运行

时间:2017-03-06 12:51:11

标签: javascript google-chrome internet-explorer firefox

我有一个带有输入的以下GET,带有一个辅助JS函数,可以在URL上添加更多内容。

<script type="text/javascript" language="javascript">
    function injectQuerySentence() {
        var userInput = document.getElementById("userInputBox").value;
        document.myformName.action += '#order=relevance&q=' + userInput;
    }
</script>

<form name='myformName' method="GET" onsubmit="injectQuerySentence()" >
    <input type="hidden" name="option" value="es" />
    <input type="hidden" name="view" value="search" />
    <input id="userInputBox"class="searchbox" type="textbox"/>
</form>

如果我将字符串hello放在表单上并按回车键,我会收到以下网址:

https://mywebsite?option=es&view=search#order=relevance&q=hello&

Chrome和Firefox中的一切正常,但它无法在Internet Explorer上运行。使用IE我只是得到这个网址:

https://mywebsite?option=es&view=search

如何让它在IE中运行?

编辑:我在ES控制台上看不到任何错误。

1 个答案:

答案 0 :(得分:0)

这是IE在处理form.action时的错误(或充其量&#34; quirk&#34;)

根据您的代码,您可以改为:

    document.myformName.action = window.location.href + '#order=relevance&q=' + userInput;

将以相同的方式更改网址。