--- title: 'Element: compositionupdate イベント' slug: Web/API/Element/compositionupdate_event tags: - Element - Event - Input method - Reference - compositionupdate translation_of: Web/API/Element/compositionupdate_event --- <div>{{APIRef}}</div> <p><strong><code>compositionupdate</code></strong> イベントは、 {{glossary("input method editor", "IME")}} などのテキスト変換システムによって制御されているテキスト変換セッションに新しい文字が入力されたときに発生します。</p> <p>例えば、このイベントは、ユーザーが<a href="https://ja.wikipedia.org/wiki/ピン音">ピン音</a> IME を使用して漢字の入力をしている最中に発生します。</p> <table class="properties"> <tbody> <tr> <th>バブリング</th> <td>あり</td> </tr> <tr> <th>キャンセル</th> <td>可</td> </tr> <tr> <th>インターフェイス</th> <td>{{domxref("CompositionEvent")}}</td> </tr> <tr> <th>イベントハンドラープロパティ</th> <td>なし</td> </tr> </tbody> </table> <h2 id="Examples" name="Examples">例</h2> <pre class="brush: js">const inputElement = document.querySelector('input[type="text"]'); inputElement.addEventListener('compositionupdate', (event) => { console.log(`generated characters were: ${event.data}`); });</pre> <h3 id="Live_example" name="Live_example">実行例</h3> <h4 id="HTML">HTML</h4> <pre class="brush: html"><div class="control"> <label for="name">On macOS, click in the textbox below,<br> then type <kbd>option</kbd> + <kbd>`</kbd>, then <kbd>a</kbd>:</label> <input type="text" id="example" name="example"> </div> <div class="event-log"> <label>Event log:</label> <textarea readonly class="event-log-contents" rows="8" cols="25"></textarea> <button class="clear-log">Clear</button> </div></pre> <div class="hidden"> <h4 id="CSS">CSS</h4> <pre class="brush: css">body { padding: .2rem; display: grid; grid-template-areas: "control log"; } .control { grid-area: control; } .event-log { grid-area: log; } .event-log-contents { resize: none; } label, button { display: block; } input[type="text"] { margin: .5rem 0; } kbd { border-radius: 3px; padding: 1px 2px 0; border: 1px solid black; } </pre> </div> <h4 id="JS">JS</h4> <pre class="brush: js">const inputElement = document.querySelector('input[type="text"]'); const log = document.querySelector('.event-log-contents'); const clearLog = document.querySelector('.clear-log'); clearLog.addEventListener('click', () => { log.textContent = ''; }); function handleEvent(event) { log.textContent = log.textContent + `${event.type}: ${event.data}\n`; } inputElement.addEventListener('compositionstart', handleEvent); inputElement.addEventListener('compositionupdate', handleEvent); inputElement.addEventListener('compositionend', handleEvent); </pre> <h4 id="Result" name="Result">結果</h4> <p>{{ EmbedLiveSample('Live_example', '100%', '180px') }}</p> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('UI Events', '#event-type-compositionupdate')}}</td> <td>{{Spec2('UI Events')}}</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat("api.Element.compositionupdate_event")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>関連イベント: {{domxref("Element/compositionstart_event", "compositionstart")}}, {{domxref("Element/compositionend_event", "compositionend")}}。</li> </ul>