搜索不在IE中工作。仅适用于Chrome

时间:2013-10-08 19:38:37

标签: javascript ajax internet-explorer search

我在搜索字段中遇到此问题。当我点击进入按钮时,搜索会被触发,但只能在Chrome中使用。如果我点击IE中的输入按钮,页面中的唯一更改,如果我点击按钮,再次进行搜索...工作。

$( document ).ready(function(event) {
        $("#searchField").keypress(function(event) {
            if (event.which == 13) {
                search_value = $('#searchField').val();
                proj_id = $('#projectId').val();
                //alert (search_value + '-' + proj_id);
                searchMeeting(search_value, proj_id);
            }

        });
    });

function searchMeeting(search_value, proj_id) {

    var lastSearchValue = $('#searchField').val();
    if (proj_id != "") {
        $.ajaxSettings.traditional = true;
        $.ajax({
            url : '../meeting/searchMeeting.action',
            type : 'post', // method
            dataType : 'html',
            data : { // data to send
                "searchValue" : search_value,
                "projectId" : proj_id
            },
            error : function() { // fail
                alert('Failed to search!');
            },
            success : function(html) {// success
                $('#backToList').attr("style","display: none;");
                $("#meeting_content").html(html);
                $("#searchField").val(lastSearchValue);
                bindTableEvents();
            }
        });
    }
}

1 个答案:

答案 0 :(得分:1)

您可以将表单提交给表单,而不是检查键码:

<form method="post">
    <input type="search" id="searchField" />
</form>

$("#searchField").closest('form').on('submit',function(event) {
    event.preventDefault();
    search_value = $('#searchField').val();
    proj_id = $('#projectId').val();
    //alert (search_value + '-' + proj_id);
    searchMeeting(search_value, proj_id);  
});

当然,您可以向表单添加ID并将事件绑定到该