OnChange 事件函数

OnChange event function

我有接下来的三个输入:

<input type="file" name="first"/>
<input type="file" name="second"/>
<input type="file" name="third"/>

如果文件被选中,我想做点什么。我有下一个功能:

$(function() {
    $('input[name="INPUT-NAME"]').change(function (){
       alert("Selected");
    });
});

有什么方法可以将单击的输入字段的 name 传递给此函数吗?

使用$(this).attr('name') method or just this.name获取name属性

$(function() {
  $('input').change(function() {
    alert("Selected" + this.name);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="file" name="first" />
<input type="file" name="second" />
<input type="file" name="third" />