Вопрос по javascript, jquery, internet-explorer – Как получить имя файла из элемента input type = file html, используя JavaScript или JQuery?

17

Error: User Rate Limit Exceeded

Как это решить?

console.log($("input[name='attachment[]']"));
/* Output:
[
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
, 
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
, 
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
]
*/

$.each($("input[name='attachment[]']"), function(i,v) {
    console.log(i);
    console.log(v); //v.val() does not exist... even uploaded a file and showing file

});

/* Output: 
0
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
1
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
2
<input type=​"file" name=​"attachment[]​" id=​"attachment">​
*/

return false;
Error: User Rate Limit Exceeded$(v)Error: User Rate Limit Exceeded Parth Thakkar
Error: User Rate Limit ExceededidError: User Rate Limit Exceededattachment1, attachment2, ..., attachmentn. sp00m
Error: User Rate Limit Exceeded Parth Thakkar
Error: User Rate Limit Exceeded$(v).val()? sp00m
Uncaught TypeError: Object #<HttmlinputElement> has no mehtod 'val'Error: User Rate Limit Exceeded$(v).val(). YumYumYum

Ваш Ответ

4   ответа
19

$("input[name='attachment[]']").each(function() {
    var fileName = $(this).val().split('/').pop().split('\\').pop();
    console.log(fileName);
});

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededstackoverflow.com/questions/27898745/…
12

​$('input:file').change(
    function(e){
        console.log(e.target.files[0].name);
    });​​​

.

multiple

$('input:file').change(
    function(e){
        var f = e.target.files,
            len = f.length;
        for (var i=0;i<len;i++){
            console.log(f[i].name);
        }
    });​

.

NOTE: in current browser versions, f[i].fileName should be f[i].name.

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded.nameError: User Rate Limit Exceeded.fileNameError: User Rate Limit Exceeded
Error: User Rate Limit Exceeded.nameError: User Rate Limit Exceeded.fileName.
4

<input type=file>files.

document.querySelector('input[type=file]').files 

document.querySelector('input[type=file]').files[0].name

, files

0

<input type="file" mutiple onchange="getSongs(this.files)"/>

function getSongs(files){
  ...
  for(var i = 0; i < files.length; i++){
     file=files[i];
     filename=file.fileName;
  }
}

$("type=['file']").attr('name');
Error: User Rate Limit Exceeded

Похожие вопросы