From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/globaleventhandlers/oninput/index.html | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 files/ja/web/api/globaleventhandlers/oninput/index.html (limited to 'files/ja/web/api/globaleventhandlers/oninput') diff --git a/files/ja/web/api/globaleventhandlers/oninput/index.html b/files/ja/web/api/globaleventhandlers/oninput/index.html new file mode 100644 index 0000000000..c9613eb8c2 --- /dev/null +++ b/files/ja/web/api/globaleventhandlers/oninput/index.html @@ -0,0 +1,93 @@ +--- +title: GlobalEventHandlers.oninput +slug: Web/API/GlobalEventHandlers/oninput +tags: + - API + - Event Handler + - GlobalEventHandlers + - HTML DOM + - Property + - Reference +translation_of: Web/API/GlobalEventHandlers/oninput +--- +
{{ApiRef("HTML DOM")}}
+ +

{{domxref("GlobalEventHandlers")}} ミックスインの oninput プロパティは、{{HTMLElement("input")}}、{{HTMLElement("select")}}、{{HTMLElement("textarea")}} の各要素上の {{event("input")}} イベントを処理する {{domxref("EventHandler")}} です。これは、{{domxref("HTMLElement.contentEditable", "contenteditable")}} または {{domxref("Document.designMode", "designMode")}} が有効になっている要素上のイベントも扱います。

+ +
+

注記: oninput と異なり、{{domxref("GlobalEventHandlers.onchange", "onchange")}} イベントハンドラーは、各要素の value が変化するたびに呼び出される必要がありません。

+
+ +

構文

+ +
target.oninput = functionRef;
+ +

+ +

functionRef は関数名または 関数式 です。この関数は、{{domxref("KeyboardEvent")}} オブジェクトとその 1 個の引数を受け取ります。

+ +

+ +

この例は、{{HtmlElement("input")}} 要素のコンテンツを変更する度に、その文字数をログ出力します。

+ +

HTML

+ +
<input type="text" placeholder="ここに何か入力すると、その長さが分かります。" size="50">
+<p id="log"></p>
+ +

JavaScript

+ +
let input = document.querySelector('input');
+let log = document.getElementById('log');
+
+input.oninput = handleInput;
+
+function handleInput(e) {
+  log.textContent = `フィールドの value は
+      ${e.target.value.length} 文字の長さです。`;
+}
+ +

実行結果

+ +

{{EmbedLiveSample("Example")}}

+ +

仕様

+ + + + + + + + + + + + + + + + +
仕様書策定状況備考
{{SpecName("HTML WHATWG", "#ix-handler-oninput", "oninput")}}{{Spec2("HTML WHATWG")}}初期定義
+ +

ブラウザー実装状況

+ + + +

{{Compat("api.GlobalEventHandlers.oninput")}}

+ +

以下のリンクは、互換性の問題と修正についての議論です。古いブラウザーで動作させる場合に役立つでしょう:

+ + + +

関連項目

+ + -- cgit v1.2.3-54-g00ecf