下拉框的 Keyup 替代方案

Keyup alternative for dropdown boxes

我目前有一个带有 id="activityField" 的搜索字段,这样每当用户更改此字段时,关联的 table 就会更新。据我所知,这是 jQuery keyup():

的结果
$(document).on('keyup', '#tableFilter', function() {
        window.location.hash = $(this).val()
        $('.spotRow').first().click()
    })

但是,我用 HTML <select id="activityFilter"> 添加了一个下拉框,但我不知道如何复制 keyup() 行为。当我在下拉列表中选择一个选项时,没有立即发生任何变化,但是如果我在#tableFilter 输入字段中点击 space,table 会按预期更新。

我可以在此下拉菜单上使用一些等效的 keyup() 吗?

你应该使用

$('#activityFilter option').on('click', function() {
   window.location.hash = $(this).val();
   $('.spotRow').first().click();
});

document 上设置您的按键侦听器可能也是个好主意。你应该给你所有的输入字段一个通用的 class,然后听那个 class.

IE:

$('.myCommonClass').on('keyup', function() {
   window.location.hash = $(this).val();
   $('.spotRow').first().click();
});