首页 > 文章列表 > 当一个元素的内容被粘贴时,在JavaScript中发生了哪个事件?

当一个元素的内容被粘贴时,在JavaScript中发生了哪个事件?

paste(粘贴) contenteditable(可编辑) onpaste(当粘贴发生时)
227 2023-09-14

当你在元素中粘贴内容时,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>