aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlelement/beforeinput_event
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/htmlelement/beforeinput_event')
-rw-r--r--files/zh-cn/web/api/htmlelement/beforeinput_event/index.html101
1 files changed, 101 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/htmlelement/beforeinput_event/index.html b/files/zh-cn/web/api/htmlelement/beforeinput_event/index.html
new file mode 100644
index 0000000000..fa11a7588c
--- /dev/null
+++ b/files/zh-cn/web/api/htmlelement/beforeinput_event/index.html
@@ -0,0 +1,101 @@
+---
+title: 'HTMLElement: beforeinput event'
+slug: Web/API/HTMLElement/beforeinput_event
+tags:
+ - Event
+ - InputEvent
+ - beforeinput
+ - 事件
+ - 参考
+ - 实验性
+translation_of: Web/API/HTMLElement/beforeinput_event
+---
+<div>{{APIRef}} {{SeeCompatTable}}</div>
+
+<p>DOM 事件 <strong><code>beforeinput</code></strong> 在{{HTMLElement("input")}}, {{HTMLElement("select")}} 或 {{HTMLElement("textarea")}} 的值即将被修改前触发。这个事件也可以在 {{domxref("HTMLElement.contentEditable", "contenteditable")}} 被设置为 <code>true</code> 的元素和打开 {{domxref("Document.designMode", "designMode")}} 后的任何元素上被触发。</p>
+
+<p>In the case of <code>contenteditable</code> and <code>designMode</code>,  the event target is the <strong>editing host</strong>. If these properties apply to multiple elements, the editing host is the nearest ancestor element whose parent isn't editable.</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th>Bubbles</th>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <th>Cancelable</th>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <th>Interface</th>
+ <td>{{DOMxRef("InputEvent")}}</td>
+ </tr>
+ <tr>
+ <th>Event handler property</th>
+ <td>None</td>
+ </tr>
+ <tr>
+ <th>Sync / Async</th>
+ <td>Sync</td>
+ </tr>
+ <tr>
+ <th>Composed</th>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <th>Default Action</th>
+ <td>Update the DOM element</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="示例">示例</h2>
+
+<p>这个例子会在 {{HtmlElement("input")}} 元素的值即将被新的值更新前记录下当前的值。</p>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;input placeholder="Enter some text" name="name"/&gt;
+&lt;p id="values"&gt;&lt;/p&gt;</pre>
+
+<h3 id="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="结果">结果</h3>
+
+<p><iframe class="live-sample-frame sample-code-frame" frameborder="0" id="frame_Examples" src="https://mdn.mozillademos.org/en-US/docs/Web/API/HTMLElement/beforeinput_event$samples/Examples?revision=1609140"></iframe></p>
+
+<h2 id="规范">规范</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="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.HTMLElement.beforeinput_event")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>相关事件:<code><a href="/en-US/docs/Web/API/HTMLElement/input_event">input</a></code></li>
+</ul>