JavaScript copy to clipboard not working

前端 未结 5 1197
感动是毒
感动是毒 2021-02-12 22:11

I have a function in my script that gives me an error. The function purpose is to copy text from static panel(not textbox or input) with onClick event.

Uncaught

5条回答
  •  半阙折子戏
    2021-02-12 22:39

    Great answer by Intervalia.

    Small improvement to it, sometimes the clicked element is not the one you want to copy.
    So I suggest you pass the id of the element you want to copy.

    
    

    Text Sample

    And then, in the first line of your function do

    element = document.getElementById(element); 
    

    Not much of a difference but I think it's more useful this way.

提交回复
热议问题