", "datePublished": "2020-07-21T05:49:05Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/azcvcza", "@type": "Person", "name": "azcvcza"}}, {"text": "逐渐 stackoverflow", "datePublished": "2020-07-21T05:57:54Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/Terry05", "@type": "Person", "name": "Terry05"}}, {"text": "@azcvcza 谢谢", "datePublished": "2020-07-21T06:39:35Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/TomeWong", "@type": "Person", "name": "TomeWong"}}, {"text": "为啥会在这问这种基础问题- -b stackoverflow 不香么", "datePublished": "2020-07-22T02:23:35Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/wednesdayco", "@type": "Person", "name": "wednesdayco"}}, {"text": "逐渐 stackoverflow", "datePublished": "2020-07-22T06:08:29Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/Sven0706", "@type": "Person", "name": "Sven0706"}}, {"text": "....", "datePublished": "2020-07-23T01:42:43Z", "@type": "Comment", "author": {"url": "https://www.v2ex.com/member/myCupOfTea", "@type": "Person", "name": "myCupOfTea"}}], "interactionStatistic": [{"userInteractionCount": 2437, "@type": "InteractionCounter", "interactionType": "https://schema.org/ViewAction"}, {"userInteractionCount": 8, "@type": "InteractionCounter", "interactionType": "https://schema.org/ReplyAction"}], "text": "
\n\n
\n\nimport Queues from './widgets/queue.js'\nclass Uploader {\nconstructor () {\nthis.container = document.getElementById('file');\nthis.queue = new Queues();\nthis.pool = [];\nthis.container.addEventListener('change', function() {\nvar filesList = document.querySelector('#files').files;\nif(filesList.length==0){ //如果取消上传,则改文件的长度为 0\nreturn;\n}else{\n//如果有文件上传,这在这里面进行\nconsole.log(filesList);\nQueues.addFile(filesList);\n}\n})\n}\n}\nexport default Uploader\n运行后,选择后,js 中的代码没有触发,求原因\n谢谢!!!", "datePublished": "2020-07-21T02:25:48Z", "commentCount": 8, "mainEntityOfPage": "https://www.v2ex.com/t/691812", "author": {"url": "https://www.v2ex.com/member/TomeWong", "@type": "Person", "name": "TomeWong"}, "headline": "html 调用 class 封装的 js,无反应", "url": "https://www.v2ex.com/t/691812", "isPartOf": {"url": "https://www.v2ex.com/go/programmer", "@type": "WebPage", "name": "程序员"}, "@context": "https://schema.org", "@type": "DiscussionForumPosting"}
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
TomeWong
V2EX  ›  程序员

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

  •  
  •   TomeWong · 2020 年 7 月 21 日 · 2437 次点击
    这是一个创建于 2094 天前的主题,其中的信息可能已经有所发展或是发生改变。
       <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 条回复    2020-07-23 09:42:43 +08:00
    ChanKc
        1
    ChanKc  
       2020 年 7 月 21 日 via Android
    new Uploader()
    maichael
        2
    maichael  
       2020 年 7 月 21 日
    你也没有实例化 Uploader 呀
    azcvcza
        3
    azcvcza  
       2020 年 7 月 21 日
    在底下另起一行<script> var uploader = new Uploader() </script>
    Terry05
        4
    Terry05  
       2020 年 7 月 21 日
    逐渐 stackoverflow
    TomeWong
        5
    TomeWong  
    OP
       2020 年 7 月 21 日
    @azcvcza 谢谢
    wednesdayco
        6
    wednesdayco  
       2020 年 7 月 22 日
    为啥会在这问这种基础问题- -b stackoverflow 不香么
    Sven0706
        7
    Sven0706  
       2020 年 7 月 22 日
    逐渐 stackoverflow
    myCupOfTea
        8
    myCupOfTea  
       2020 年 7 月 23 日
    ....
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5634 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 03:30 · PVG 11:30 · LAX 20:30 · JFK 23:30
    ♥ Do have faith in what you're doing.