0

我在搜索字段中遇到了这个问题。当我点击输入按钮时,搜索会被触发,但只能在 Chrome 中成功运行。如果我在 IE 中点击 enter 按钮,页面中唯一的变化,如果我点击按钮,第二次进行搜索......工作。

$( 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();
            }
        });
    }
}
4

1 回答 1

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 并将事件绑定到该表单

于 2013-10-08T19:47:35.830 回答