Click button copy to clipboard using jQuery

前端 未结 21 2096
醉话见心
醉话见心 2020-11-21 23:11

How do I copy the text inside a div to the clipboard? I have a div and need to add a link which will add the text to the clipboard. Is there a solution for this?

         


        
21条回答
  •  悲哀的现实
    2020-11-21 23:50

    clipboard.js is a nice utility that allows copying of text or HTML data to the clipboard without use of Flash. It's very easy to use; just include the .js and use something like this:

    
    
    
    

    clipboard.js is also on GitHub.

    Edit on Jan 15, 2016: The top answer was edited today to reference the same API in my answer posted in August 2015. The previous text was instructing users to use ZeroClipboard. Just want to be clear that I didn't yank this from jfriend00's answer, rather the other way around.

提交回复
热议问题