粘贴元素内容时,JavaScript 中会发生哪个事件?

htmljavascriptprogramming scripts

在元素中粘贴内容时会发生 onpaste  事件。

示例

您可以尝试运行以下代码,以了解如何在 JavaScript 中使用 onpaste  事件。

<!DOCTYPE html>
<html>
    <body>
      <input type="text" onpaste="pasteFunction()" value="paste text here">
      <script>
         function pasteFunction() {
            document.write("Text pasted successfully!");
         }
      </script>
   </body>
</html>

相关文章