我有接下来的三个输入:
<input type="file" name="first"/>
<input type="file" name="second"/>
<input type="file" name="third"/>
如果选择了文件,我想做一些事情。我有下一个功能:
$(function() {
$('input[name="INPUT-NAME"]').change(function (){
alert("Selected");
});
});
有什么方法可以将单击的输入字段的名称
传递给此函数吗?
最佳答案
使用$(this).attr('name')
方法或只是 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" />
关于jquery - OnChange事件函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100350/