0

I was able to create a simple web-page that uses clipboard.js with a button that pastes predefined text using the
data-clipboard-text="Just because you can doesn't mean you should — clipboard.js" property as the documentation at the clipboard.js site shows, but now I want to place some text in a <span> tag and copy it when this text is selected.

However, I don't know how to 'tie' the data-clipboard-action="copy" data-clipboard-target="span" properties to a <span> tag and cause it to copy the <span>'s content with the onselect event.

Are there procedural statements that I can use in javaScript to perform the copying and pasting functions?

My goal is to embed code to copy selected text into the HTML part of an email and allow the recipient of the email to simply copy the selected text to the clipboard so that it can then be pasted from the clipboard into an input text box in a web-application's page.

This would simplify copy/paste on touch-screen devices, such as tablets and cell-phones.

4

2 回答 2

0

您可以使用此代码来获取屏幕的选择,并可以使用“成功”和“错误”事件。阅读剪贴板js的事件和高级部分

var clipboard = new ClipboardJS('button', {
  text: function (trigger) {
     return document.getSelection().toString()
  }
});
于 2019-10-18T10:15:54.390 回答
0

请参阅 iAmADeveloper 的评论以获取答案。

谢谢,iAmADeveloper。

于 2019-10-22T10:04:57.130 回答