V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
TomeWong
V2EX  ›  程序员

html 调用 class 封装的 js,无反应

  •  
  •   TomeWong · Jul 21, 2020 · 2467 views
    This topic created in 2107 days ago, the information mentioned may be changed or developed.
       <div class="uploader">
          <input type="file" id="file" multiple>
       </div>
       <script src="../src/index.js" type="module"></script>
    
    import Queues from './widgets/queue.js'
    
    class Uploader {
       constructor () {
          this.container = document.getElementById('file');
    
          this.queue = new Queues();
    
          this.pool = [];
    
          this.container.addEventListener('change', function() {
             var filesList = document.querySelector('#files').files;
                if(filesList.length==0){         //如果取消上传,则改文件的长度为 0         
                   return;
                }else{  
                   //如果有文件上传,这在这里面进行
                   console.log(filesList);
                   Queues.addFile(filesList);
                }
            })
        }
    }
    
    export default Uploader
    

    运行后,选择后,js 中的代码没有触发,求原因

    谢谢!!!

    8 replies    2020-07-23 09:42:43 +08:00
    ChanKc
        1
    ChanKc  
       Jul 21, 2020 via Android
    new Uploader()
    maichael
        2
    maichael  
       Jul 21, 2020
    你也没有实例化 Uploader 呀
    azcvcza
        3
    azcvcza  
       Jul 21, 2020
    在底下另起一行<script> var uploader = new Uploader() </script>
    Terry05
        4
    Terry05  
       Jul 21, 2020
    逐渐 stackoverflow
    TomeWong
        5
    TomeWong  
    OP
       Jul 21, 2020
    @azcvcza 谢谢
    wednesdayco
        6
    wednesdayco  
       Jul 22, 2020
    为啥会在这问这种基础问题- -b stackoverflow 不香么
    Sven0706
        7
    Sven0706  
       Jul 22, 2020
    逐渐 stackoverflow
    myCupOfTea
        8
    myCupOfTea  
       Jul 23, 2020
    ....
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3743 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 04:29 · PVG 12:29 · LAX 21:29 · JFK 00:29
    ♥ Do have faith in what you're doing.