0

I'm trying to collect and prepend the filename of the selected input file into a table:

HTML

<div class="row-fluid">
  <div class="span12" id="upload-modal-button">
    <span class="btn btn-small btn-success fileinput-button">
      <span>Browse</span>
      <input type="file" name="file_1" enctype="multipart/form-data" />
    </span>
  </div>
</div>

<div class="row-fluid" id="image-table">
  <div class="span12">
    <table class="table table-striped" id="upload-list">
      <thead>
        <td>Filename</td>
        <td>State</td>
        <td>Rate</td>
      </thead>
      <tr id="filelist"></tr>
    </table>
  </div>
</div>

JQUERY

$('input[type=file]').change(function(e){
  $('#filelist').prepend('<td>'+$(this).val()+'</td>');
});

But I cant get the filename to display in the table.

4

1 に答える 1

1

「jquery 1.8」を使用している場合、セレクター「type=file」は正しく機能しますが、「jquery 1.6」を使用している場合、このセレクターは機能しません。正しい方法は、このタイプのセレクターを使用することです。

$('input[type="file"]')

または、この型セレクターをクラスで使用できます。

HTML:

<input class="input-type-file" type="file" name="file_1" enctype="multipart/form-data" />

JS:

$('.input-type-file')
于 2012-10-07T14:21:04.247 に答える