doutiaoku4495 2010-07-19 14:40
浏览 117
已采纳

jQuery:如何获取文件上传输入字段的“值”

Is it possible to determine if the user has selected a file for a particular input type="file" field using javascript/jQuery?

I have developed a custom fieldtype for ExpressionEngine (PHP-based CMS) that lets users upload and store their files on Amazon S3, but the most popular EE hosting service has set a max_file_uploads limit of 20. I'd like to allow the user to upload 20 files, edit the entry again to add 20 more, etc. Unfortunately upon editing the entry the initial 20 files have a "replace this image" file input field that appears to be knocking out the possibility of uploading new images. I'd like to remove any unused file input fields via javascript when the form is submitted.

  • 写回答

3条回答 默认 最新

  • dongquxiao8545 2010-07-19 14:49
    关注

    Yes - you can read the value and even bind to the change event if you want.

    <html>
    <head>
      <title>Test Page</title>
      <script src="http://code.jquery.com/jquery-latest.js"></script>
      <script type="text/javascript">
      $(function()
      {
        $('#tester').change( function()
        {
          console.log( $(this).val() );
        });
      });
      </script>
    </head>
    
    <body>
    
    <input type="file" id="tester" />
    
    </body>
    </html>
    

    But there are other, multiple-upload solutions that might suit your needs better, such as bpeterson76 posted.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图