当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - jquery-forms multiple file input fieldValue()

问题描述:

I am using jquery forms and I have a multiple file input. I want to show the name of the files selected before submission. I can use the fieldValue method as below for a single file; however, contrary to my expectations, fieldValue() returns an array with a single element, even when multiple files are selected.

.on('change', function(event){

var fArray = $("#upload :file").fieldValue();

var nameStr = "";

for(var i = 0 ; i < fArray.length ; i++ ){

...

I looked in the chrome debugger and can find the file names. event.currentTarget.files but I don't know how to get them from jquery/javascript. Can anyone help?

Thanks.

网友答案:

You're firing an event, and to keep this code portable, it's best to do your actions on the event itself instead of a specific item.

var fArray = event.currentTarget.files;

will do what you're after.

分享给朋友:
您可能感兴趣的文章:
随机阅读: