2023年11月25日发(作者:)

H5】使⽤h5实现复制粘贴功能

⽅案⼀ 可满⾜⼤部分浏览器正常使⽤

DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>copy exampletitle>

head>

<body>

<p>

<button class="copy">Copybutton>

p>

<p>

<textarea cols="50" rows="10" placeholder="这这⾥粘贴试⼀下吧!">textarea>

p>

<script>

var copyBtn = elector('.copy')

// 点击的时候调⽤ copyTextToClipboard() ⽅法就好了.

k = function() {

copyTextToClipboard('随便复制点内容试试')

}

function copyTextToClipboard(text) {

var textArea = Element("textarea")

on = 'fixed'

= 0

= 0

= '2em'

= '2em'

g = 0

= 'none'

e = 'none'

dow = 'none'

ound = 'transparent'

= text

Child(textArea)

()

try {

var msg = mmand('copy') ? '成功' : '失败'

alert('复制内容 ' + msg);

} catch (err) {

alert('不能使⽤这种⽅法复制内容');

}

Child(textArea)

}

script>

body>

html>

⽅案⼆: 兼容苹果 iphone js 复制功能

<script src="你的路径">script>

<textarea id="bar" cols="62" rows="5" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"> 代码改变世界 textarea>

<button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar">

Cut to clipboard

button>

<script>

var clipboard = new Clipboard('.btn');

('success', function(e) {

('Action:', );

('Text:', );

('Trigger:', r);

alert("复制成功");

election();

});

('error', function(e) {

('Action:', );