在HTML中复制元素的内容时执行脚本?

当用户剪切元素的文本时,oncopy 属性将在HTML中触发。

示例

您可以尝试运行以下代码以实现oncopy 属性-

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" oncopy="display()" value = "Copy me">
      <h2 id = "test">Try to copy the above text.</h2>
      <script>
         function display() {
            document.getElementById("test").innerHTML = "您复制的文字有效!";
         }
      </script>
   </body>
</html>