2023-12-18 13:12:25 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2024-01-16 21:26:16 +08:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
2023-12-18 13:12:25 +08:00
|
|
|
<title>target-input</title>
|
2024-01-16 21:26:16 +08:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
</head>
|
|
|
|
<body>
|
2023-12-18 13:12:25 +08:00
|
|
|
<!-- 1. Define some markup -->
|
2024-01-16 21:26:16 +08:00
|
|
|
<input id="foo" type="text" value="hello" />
|
|
|
|
<button
|
|
|
|
class="btn"
|
|
|
|
data-clipboard-action="copy"
|
|
|
|
data-clipboard-target="#foo"
|
|
|
|
>
|
|
|
|
Copy
|
|
|
|
</button>
|
2023-12-18 13:12:25 +08:00
|
|
|
|
|
|
|
<!-- 2. Include library -->
|
|
|
|
<script src="../dist/clipboard.min.js"></script>
|
|
|
|
|
|
|
|
<!-- 3. Instantiate clipboard -->
|
|
|
|
<script>
|
2024-01-16 21:26:16 +08:00
|
|
|
var clipboard = new ClipboardJS('.btn');
|
2023-12-18 13:12:25 +08:00
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
clipboard.on('success', function (e) {
|
|
|
|
console.info('Action:', e.action);
|
|
|
|
console.info('Text:', e.text);
|
|
|
|
console.info('Trigger:', e.trigger);
|
|
|
|
});
|
2023-12-18 13:12:25 +08:00
|
|
|
|
2024-01-16 21:26:16 +08:00
|
|
|
clipboard.on('error', function (e) {
|
2023-12-18 13:12:25 +08:00
|
|
|
console.log(e);
|
2024-01-16 21:26:16 +08:00
|
|
|
});
|
2023-12-18 13:12:25 +08:00
|
|
|
</script>
|
2024-01-16 21:26:16 +08:00
|
|
|
</body>
|
2023-12-18 13:12:25 +08:00
|
|
|
</html>
|