HTML onpaste イベント属性

❮ HTML イベント属性

<input> 要素のテキストを貼り付けるときに JavaScript を実行します:

<input type="text" onpaste="myFunction()" value="Paste something in here">
Try it Yourself ❯

他の "Try it Yourself" の例が下にあります。


定義と用法

onpaste 属性は、ユーザが要素を貼り付けるときに発火します

注: onpaste 属性はすべての HTML 要素でサポートされていますが、例えば、 <p> 要素の contenteditable 属性に "true" が設定されていない限り、実際に要素のコンテンツを貼り付けることはできません (下の「その他の例」を参照)。

チップ: 大抵の場合、onpaste 属性は、type="text" の<input> 要素で使用されます。

チップ: 要素のコンテンツを貼り付けるには、次の 3 つの方法があります:


ブラウザ・サポート

イベント属性
onpaste Yes Yes Yes Yes Yes

HTML 4.01 と HTML5 の相違点

なし。


構文

<element onpaste="script">

属性値

説明
script script は onpaste で実行される

技術的詳細

サポートする HTML タグ: ALL HTML elements

Examples

その他の例

<p> 要素のテキストを貼り付けるときに JavaScript を実行します (contenteditable を "true" に設定することに注意してください):

<p contenteditable="true" onpaste="myFunction()">Try to paste something inside this paragraph.</p>
Try it Yourself ❯

関連ページ

HTML reference: oncopy event

HTML reference: oncut event

HTML DOM リファレンス:onpaste イベント


HTML Event Attributes HTML イベント属性