我有4个文件输入,我希望它们的值发生更改时触发上传过程。 我的意思是,当您选择一张图片并在选择图像对话框上单击打开时,将触发上传图片的脚本。我用onchange事件,但我认为这是不正确的事件:文件输入元素的更改事件
JS:
$("input[type=file]").on('change',function(){
alert(this.val());//I mean name of the file
});
HTML:
<div class="form-group col-md-11 col-md-offset-1">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
</div>
我该怎么办?
可能重复[?如何开始前让所有图像文件名上传](http://stackoverflow.com/questions/18400686/how-to-all-image-file-name-before-start-upload)或http://stackoverflow.com/questions/1804745/get-the-filename-through-javascript – ahren
val()是一个jquery函数,但是你的上下文中的this是一个DOM对象。试试'this.value'或$(this).val()'看看会发生什么。 –