javascript - Firefox JavaScript 表单

标签 javascript forms firefox struts

我有下面的jsp代码。我遇到了 Firefox 在 get 方法中发送与 Internet Explorer 不同的参数的问题。有什么想法吗?

这是获取网址:

Internet 浏览器: http://www.example.com/app/search/SkillSearch.do?dispatch=skillSearch2&textSearch=test&search=&searchField=test&searchType=

火狐: http://www.example.com/app/search/SearchPeople.do?dispatch=&textSearch=&search=&searchField=test&searchType=

<script>
function doSearch(selection,searchInfo){
    // Get the Search Bar Form
    var searchForm = document.getElementById('searchBarForm').firstChild;

    // Get the dispatch input in the Search Bar Form
    var searchFormChildren = searchForm.childNodes;
    var dispatch;
    for (var i=0; i<searchFormChildren.length; i++) {
        if (searchFormChildren[i].name == "dispatch") {
            dispatch = searchFormChildren[i];
            break;
        }
    }

    // Variable to hold search input
    var searchField;

    // Set form variables depending on type of search selected
    if (selection.selectedIndex == "0") {
        dispatch.value = "skillSearch2";
        searchForm.action = "/app/search/SkillSearch.do";

        for (var i=0; i<searchFormChildren.length; i++) {
            if (searchFormChildren[i].name == 'textSearch') {
                searchField = searchFormChildren[i];
                break;
            }
        }
    }
    else if (selection.selectedIndex == "1") {
        dispatch.value = "searchPeople";
        searchForm.action = '/app/search/SearchPeople.do';

        for (var i=0; i<searchFormChildren.length; i++) {
            if (searchFormChildren[i].name == 'search') {
                searchField = searchFormChildren[i];
                break;
            }
        }
    }
    else if (selection.selectedIndex == "2") {
        dispatch.value="search";
        searchForm.action = '/app/search/LinkSearch.do';

        for (var i=0; i<searchFormChildren.length; i++) {
            if (searchFormChildren[i].name == 'search') {
                searchField = searchFormChildren[i];
                break;
            }
        }
    }

    searchField.value = searchInfo.value;
    searchForm.submit();
}

function checkKeyPress(selection, searchInfo) {
    if (window.event && window.event.keyCode == 13) {
        doSearch(selection, searchInfo);
    }
}
</script>

<logic:present name="SSO_TOKEN" scope="session">
    <p id="searchBarForm">
        <html:form action="/search/SearchPeople.do" method="get">
            <input type="hidden" name="dispatch" value=""/>
            <input type="hidden" name="textSearch" value="" />          <input type="hidden" name="search" value="" /> 
            <input size="15" name="searchField" value="Search" onfocus="if (this.value == 'Search') this.value = '';" onkeypress="checkKeyPress(searchType, searchField)"/>&nbsp;&nbsp;&nbsp;&nbsp;
            <select class="select" name="searchType" size="1" style="font-size: 13px;" onkeypress="checkKeyPress(searchType, searchField)">
                <option value="" selected>Subject Matter Experts</option>
                <option value="">Users</option>
            </select>&nbsp;&nbsp;&nbsp;&nbsp;
            <input class="button" type="button" value="Search" onclick="doSearch(searchType, searchField)" />
        </html:form>
    </p>
</logic:present>

最佳答案

Validate. Validate. Validate.段落不能包含表单,并且不同的浏览器似乎以不同的方式从该错误中恢复。

此外,不要假设第一个元素和第一个子元素相同。当您有:<foo> <bar></bar> </foo>时,某些浏览器将创建一个完全由空格组成的textNode。 .

关于javascript - Firefox JavaScript 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5760766/

相关文章:

javascript - api请求后,数组在控制台中被拆分为多个数组

css - SVG 微笑 : animateTransform replace to set(opacity and scale attributes)

javascript - 重复下拉 Javascript 对第二个下拉菜单元素的影响

javascript - 如何使用 Vanilla JS 隐藏 API key

javascript - 从 VB.NET 到 JavaScript 通过 WebMethod 获取 SessionID

jquery - 如何使用 jQuery 重新填充表单提交上的隐藏 CSV 字段

javascript - 在表单中使用 JavaScript 进行计算,输出到动态字段,代码不起作用

php - 在 POST 上生成并保存序列号

javascript - grunt.js - 将 javascript 连接到函数调用中

javascript - Firefox 糟糕的 RegEx 性能