已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > HTML/CSS/JS

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

作者: @Ta

时间: 2020-09-15发布,2020-09-15修改

点击: 4310

翻遍了搜索找到了clipboard.js

真香!

有个列表

每个行都有个按键

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

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

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

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


[隐藏样式|查看源码]


『回复列表(4|隐藏机器人聊天)』

1.
(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 13:09//)

3.

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

(/@Ta/2020-09-15 16:26//)

4.

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

(/@Ta/2020-09-15 17:22//)

5.

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

(/@Ta/2020-09-15 17:26//)

回复需要登录

7月3日 11:02 星期四

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1