2023年11月25日发(作者:)
JS实现点击按钮复制内容到粘贴板clipboard
具体实现如下:
body {
text-align: center;
}
#p1 {
line-height: 150px;
font-size: 40px;
}
#source {
font-size: 18px;
}
.wrapper {
margin-top: 50px;
}
.btn {
width: 300px;
height: 120px;
background-color: #4da2fd;
color: #fff;
font-size: 20px;
text-decoration: none;
margin-top: 10px;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
#result {
width: 100%;
*/
function copyText() {
var inputEle = Element('input');
on = 'fixed';
= '100000px';
// = mentById("source").value;
= mentById("p1").innerText;
(inputEle);
();
var isSuccess = mmand("copy");
mentById('result').innerText = isSuccess ? "⽂字复制成功!" : "⽂字复制失败!";
Child(inputEle);
}
/**
* ⽅法2: 使⽤ , 具体⽤法看对应⽂档
*
* 注意事项:
* - 实现和⽅法1⼤体⼀样
* - 链接: /zenorocha//tree/2b48909ff1fb6da1378a3a6bc81a61a67f629dc2
发布评论