jQuery 如何区分更改了哪个“<select id=" value/ID?

jQuery How to differentiate which "<select id=" value/ID was changed?

我的主要问题是,如何区分更改了哪个下拉框? 本质上,我有这个 HTML 下拉列表代码 boxes/ComboBoxes,它由 JS 中的 JSON 文件填充。

            <select id="filterCountry">
              <option value="0">All Countries</option>
            </select>
            <select id="filterBrowser">
              <option value="0">All Browsers</option>
            </select>
            <select id="filterOS">
              <option value="0">All Operating System</option>
            </select>

我的 jQuery 代码现在与此类似。

$("#filterBrowser, #filterOS, #filterCountry").change(function(e){
    alert("Something has been changed "  + this.value);

    // Ugly pseudocode but something along the lines of...
    if(("#filterBrowser").change) {
        console.log("the browser drop down was changed");
    } else if (("#filterOS").change) {
        console.log("The OS drop down changed");
    } else if(("#filterCountry").change) {
        console.log("The country drop down was changed")
    }
});

您可以获得引发事件的元素的id。例如:

if(this.id === 'filterBrowser') {
  //...
}