aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmlelement/beforeinput_event/index.html
blob: 4939f3e9b8d3e50258df591b9c644d36de0a9b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: 'HTMLElement: beforeinput イベント'
slug: Web/API/HTMLElement/beforeinput_event
tags:
  - DOM
  - Event
  - Experimental
  - InputEvent
  - Reference
  - beforeinput
translation_of: Web/API/HTMLElement/beforeinput_event
---
<div>{{APIRef}} {{SeeCompatTable}}</div>

<p><span class="seoSummary">DOM の <strong><code>beforeinput</code></strong> イベントは、{{HTMLElement("input")}}{{HTMLElement("select")}}、または {{HTMLElement("textarea")}} 要素の値が変更されようとしているときに発生します。 このイベントは、{{domxref("HTMLElement.contentEditable", "contenteditable")}} が有効になっている要素、および {{domxref("Document.designMode", "designMode")}} がオンになっている要素にも適用されます。</span></p>

<p><code>contenteditable</code><code>designMode</code> の場合、イベントのターゲットは<em>編集ホスト</em>です。 これらのプロパティが複数の要素に適用された場合、編集ホストは、親が編集可能ではない直近の先祖要素になります。</p>

<table class="properties">
 <tbody>
  <tr>
   <th>バブリング</th>
   <td>あり</td>
  </tr>
  <tr>
   <th>キャンセル</th>
   <td></td>
  </tr>
  <tr>
   <th>インターフェイス</th>
   <td>{{DOMxRef("InputEvent")}}</td>
  </tr>
  <tr>
   <th>イベントハンドラプロパティ</th>
   <td>なし</td>
  </tr>
  <tr>
   <th>同期 / 非同期</th>
   <td>同期</td>
  </tr>
  <tr>
   <th>Composed</th>
   <td>はい</td>
  </tr>
  <tr>
   <th>デフォルトのアクション</th>
   <td>DOM 要素の更新</td>
  </tr>
 </tbody>
</table>

<h2 id="Examples" name="Examples"></h2>

<p>この例では、{{HtmlElement("input")}} 要素の値を変更する直前に値を記録します。</p>

<h3 id="HTML" name="HTML">HTML</h3>

<pre class="brush: html">&lt;input placeholder="テキストを入力" name="name"/&gt;
&lt;p id="values"&gt;&lt;/p&gt;</pre>

<h3 id="JavaScript" name="JavaScript">JavaScript</h3>

<pre class="brush: js">const input = document.querySelector('input');
const log = document.getElementById('values');

input.addEventListener('beforeinput', updateValue);

function updateValue(e) {
  log.textContent = e.target.value;
}</pre>

<h3 id="Result" name="Result">結果</h3>

<p>{{EmbedLiveSample("Examples")}}</p>

<h2 id="Specifications" name="Specifications">仕様</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">仕様</th>
   <th scope="col">状態</th>
  </tr>
  <tr>
   <td>{{SpecName('UI Events', "#event-type-beforeinput", "beforeinput event")}}</td>
   <td>{{Spec2('UI Events')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>



<p>{{Compat("api.HTMLElement.beforeinput_event")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>関連イベント: <code><a href="/ja/docs/Web/API/HTMLElement/input_event">input</a></code></li>
</ul>