aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/globaleventhandlers/oninput
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/globaleventhandlers/oninput
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/globaleventhandlers/oninput')
-rw-r--r--files/zh-cn/web/api/globaleventhandlers/oninput/index.html81
1 files changed, 81 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/globaleventhandlers/oninput/index.html b/files/zh-cn/web/api/globaleventhandlers/oninput/index.html
new file mode 100644
index 0000000000..6118a8cc8e
--- /dev/null
+++ b/files/zh-cn/web/api/globaleventhandlers/oninput/index.html
@@ -0,0 +1,81 @@
+---
+title: GlobalEventHandlers.oninput
+slug: Web/API/GlobalEventHandlers/oninput
+tags:
+ - API
+ - Event Handler
+translation_of: Web/API/GlobalEventHandlers/oninput
+---
+<div>{{ ApiRef("HTML DOM") }}</div>
+
+<p>{{domxref("GlobalEventHandlers")}}mixin的<code><strong>oninput</strong></code>属性是{{domxref("EventHandler")}},它处理{{HTMLElement("input")}},{{HTMLElement("select")}}和 {{HTMLElement("textarea")}} 元素上的 {{event("input")}} 事件。 它还会在{{domxref("HTMLElement.contentEditable", "contenteditable")}} 或 {{domxref("Document.designMode", "designMode")}}打开的元素上处理这些事件。</p>
+
+<div class="blockIndicator note">
+<p>注意:与<code>oninput</code>不同的是, {{domxref("GlobalEventHandlers.onchange", "onchange")}} 事件处理程序不一定会针对元素值的每次更改而调用。</p>
+</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>target</em>.oninput = <em>functionRef</em>;</pre>
+
+<h3 id="值">值</h3>
+
+<p><code>functionRef</code>是一个函数名或函数表达式。该函数接收{{domxref("InputEvent")}} 对象作为唯一参数。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;input type="text" placeholder="Type something here to see its length."size="50"&gt; &lt;p id="log"&gt;&lt;/p&gt;</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">let input = document.querySelector('input');
+let log =document.getElementById('log');
+input.oninput = handleInput;
+function handleInput(e) {
+  log.textContent = `The field's value is${e.target.value.length} character(s) long.`;
+}</pre>
+
+<h3 id="结果">结果</h3>
+
+<p>{{EmbedLiveSample("示例")}}</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("HTML WHATWG", "#ix-handler-oninput", "oninput")}}</td>
+ <td>{{Spec2("HTML WHATWG")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.GlobalEventHandlers.oninput")}}</p>
+
+<p>The following links discuss compatibility issues and fixes that may be helpful when working with older browsers:</p>
+
+<ul>
+ <li><a href="http://blog.danielfriesen.name/2010/02/16/html5-browser-maze-oninput-support/">A HTML5 Browser maze, oninput support</a></li>
+ <li><a href="http://www.useragentman.com/blog/2011/05/12/fixing-oninput-in-ie9-using-html5widgets/">Fixing oninput in IE Using html5Widgets</a> includes polyfill for IE6-8</li>
+ <li>Mathias Bynens suggests <a href="http://mathiasbynens.be/notes/oninput">binding to both input and keydown</a></li>
+ <li><a href="http://help.dottoro.com/ljhxklln.php">oninput event | dottoro</a> has notes about bugginess in IE9</li>
+ <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=312094">Bug 312094 - Add support for &lt;select oninput&gt;</a></li>
+</ul>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{event("input")}} </li>
+</ul>