javascript - nodejs怎么模拟input type=file拿到filelist
阿神
阿神 2017-04-11 12:55:58
[JavaScript讨论组]

nodejs怎么得到html中点击<input type="file">选中文件后得到的filelist

阿神
阿神

闭关修行中......

全部回复(2)
阿神
  • TALK IS CHECAP, SHOW ME THE CODE

<html>
<body>
  <form>
      <p>
        <label>Select file to upload</label>
        <input type="file">
      </p>
      <button id="taozhi" type="submit">Convert</button>
    </form>
  <script>      
        var p = document.getElementById("taozhi");
        p.onclick = showAlert;
    

      function showAlert(event) {
        // 这就是你需要的吧!!input.files获取选中文件之后的filelist
        const input = document.querySelector('input[type="file"]')
        const file = input.files[0]
        let formData = new FormData();  
        formData.append('image', file);
        fetch('http://localhost:8001/upload',{  
            method:'post',
            body:formData,  
        })  
        .then((response) => response.json() )  
        .then((response)=>{  
          console.log(response)
        })  
        .catch((err)=>console.error(err)); 
      }
    </script>
</body>
</html>
阿神

一般模拟的问题都可以用phantomjs解决吧,只是效率问题

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号