【问题标题】:Rails file_field tag not showing selected file nameRails file_field 标记未显示所选文件名
【发布时间】:2021-10-11 16:19:03
【问题描述】:

即使在选择文件后,rails file_field 也不会显示所选文件名。

代码:

= f.file_field :import_csv

【问题讨论】:

    标签: ruby-on-rails filefield


    【解决方案1】:

    我的第一个解决方案是添加 JS。

    JS代码:

    $('#model_import_csv').on('change', (e) => {
      var fileName = e.target.files[0].name;
      $('#import_csv_label').html(fileName);
    });
    

    Rails 查看代码:

    = f.file_field :import_csv
    = %label#import_csv_label
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多