xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

input change only trigger once bug

input change only trigger once bug

clear first

https://stackoverflow.com/a/11280934/5934465

upload Excel once bug

solution


    uploadExcelFile() {
      // $refs / $el
      const file = document.querySelector(`[data-uid="input"]`);
      const isBind = file.dataset.isBind || false;
      log(`change 1`);
      if(!isBind) {
        // once
        file.dataset.isBind = true;
        file.addEventListener(`change`, () => {
          log(`change ...`);
          this.blob = file.files[0];
          const {
            name,
            type,
            size,
          } = this.blob;
          this.size = `文件大小: ` + size / 1000 + `KB`;
          this.filename = `文件名: ` + name;
        }, false);
        file.addEventListener(`click`, () => {
          log(`click `);
          // clear
          file.value = ``;
          // e.target.value = '';
        }, false);
      }
      file.click();
    },


posted @ 2020-02-24 17:32  xgqfrms  阅读(178)  评论(2编辑  收藏  举报