(已解决)请教个js的问题

@Ta 2020-09-15发布,2020-09-15修改 4302点击

翻遍了搜索找到了clipboard.js

真香!

有个列表

每个行都有个按键

点击这个按键复制这一行的制定内容

或者复制这个按钮里的指定值

具体格式可以看下:https://bt.18sui.net

Screenshot_2020-09-15-12-35-23-355_com.android.chrome.jpg
小尾巴我就菜鸡一枚 https://18sui.net炮兵学院

回复列表(4|隐藏机器人聊天)
  • @Ta / 2020-09-15 / /

    (31]$UNOX]NLDF2Z77)~U)K.png

     public copyText(text, callback){
        let txtArea = document.createElement("textarea");
        txtArea.id = 'txt';
        txtArea.style.position = 'fixed';
        txtArea.style.top = '0';
        txtArea.style.left = '0';
        txtArea.style.opacity = '0';
        txtArea.value = text;
        document.body.appendChild(txtArea);
        txtArea.select();
    
        try {
          let successful = document.execCommand('copy');
          if (successful) {
            callback();
            return true;
          }
        } catch (err) {
          console.log('Oops, unable to copy');
        } finally {
          document.body.removeChild(txtArea);
        }
        return false;
      }
    


    调用方式 
     copyText('复制内容',()=>{
    
    alert('复制完成')
    })
    
    
  • @Ta / 2020-09-15 / /

    @胡椒舰长,太高级了没看懂
    小尾巴我就菜鸡一枚 https://18sui.net炮兵学院

  • @Ta / 2020-09-15 / /

    @卷心菜,目测是装了火绒的且把状态栏设置在上边的并且打开了webStorm的win10系统.
    红米Note4超高配版(银色)

  • @Ta / 2020-09-15 / /

    @布偶
    大致思路就是
    使用copyText函数创建了一个可以编辑的文本框,
    并且设置其样式为"假装看不见",
    设置其内容为你要复制的文本,
    然后设置光标全选刚才的文本框内容,
    执行系统copy命令,
    复制结束后
    做一下善后处理.
    红米Note4超高配版(银色)

添加新回复
回复需要登录