如何在jQuery中识别所选的选择器?

Mis*_*hko 2 javascript jquery

$('#select_id1, #select_id2, #select_id3').change(function() {
    // If '#select_id1' has changed, 'str' should be equal to 'select_id1'.
    // If '#select_id2' has changed, 'str' should be equal to 'select_id2'.
    // If '#select_id3' has changed, 'str' should be equal to 'select_id3'.
    str = <what should be here ?>
});
Run Code Online (Sandbox Code Playgroud)

rah*_*hul 5

您可以获取调用更改的元素的ID this.id.

$('#select_id1, #select_id2, #select_id3').change(function() {
    str = this.id;
});
Run Code Online (Sandbox Code Playgroud)