oncut event
oncut Event
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <input type="text" oncut="myFunction()" value="尝试剪切该文本"> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "你剪切了文本!"; } </script> </body> </html>
Run Instance»
Click "Run Instance" button to view online examples
See more examples at the bottom of this article.
Definition and Usage
The oncut event is triggered when the user cuts the content of an element.
Note: Although the HTML elements used all support the oncut event, not all elements are actually supported, such as the <p> element. Unless contenteditable is set to "true" (see below for more examples).
Tips: The oncut event is usually applied in the <input> element of type="text".
Tips: There are three ways to cut content:
- Press CTRL + X
- and select " from the browser's edit menu Cut"
- Right-click the mouse button and select the "Cut" command in the context menu.
Browser support
Syntax
HTML:
< ;element oncut="myScript">Try it
In JavaScript:
object.oncut=function(){myScript}; Try it
In JavaScript, use the addEventListener() method:
object .addEventListener("cut", myScript); Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener( ) method.
Technical details
Whether bubbling is supported: | Yes |
---|---|
Can be canceled: | Yes |
Event type: | ClipboardEvent |
Supported HTML tags: | All HTML elements |
##More examples
Instance
Run Instance»Click the "Run Instance" button to view the online instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p contenteditable="true" oncut="myFunction()">尝试剪切该文本</p> <script> function myFunction() { alert("你剪切了文本!"); } </script> </body> </html>
Run Instance»Click the "Run Instance" button to view the online instance
Related pagesHTML DOM Reference Manual: oncopy eventHTML DOM Reference Manual: onpaste event