Firefox javascript表单

时间:2011-04-22 22:44:50

标签: javascript forms firefox struts

我在下面有以下jsp代码。我遇到的问题是Firefox在get方法中发送的不同参数比Interenet Explorer更多。有什么想法吗?

以下是获取网址:

Internet Explorer: 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>

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:1)

大卫多尔沃德的回答很明显。在http://software.hixie.ch/utilities/js/live-dom-viewer/saved/949比较IE和Firefox(这或多或少是你的标记,假设你正在提供怪癖模式文档)