aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/keyboardevent/initkeyevent
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/keyboardevent/initkeyevent
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/keyboardevent/initkeyevent')
-rw-r--r--files/zh-cn/web/api/keyboardevent/initkeyevent/index.html85
1 files changed, 85 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/keyboardevent/initkeyevent/index.html b/files/zh-cn/web/api/keyboardevent/initkeyevent/index.html
new file mode 100644
index 0000000000..649f129548
--- /dev/null
+++ b/files/zh-cn/web/api/keyboardevent/initkeyevent/index.html
@@ -0,0 +1,85 @@
+---
+title: KeyboardEvent.initKeyEvent()
+slug: Web/API/KeyboardEvent/initKeyEvent
+tags:
+ - API
+ - DOM
+ - KeyboardEvent
+ - Method
+ - 参考
+translation_of: Web/API/KeyboardEvent/initKeyEvent
+---
+<p> </p>
+
+<p>{{ ApiRef("DOM Events") }}{{non-standard_header}}{{deprecated_header}}</p>
+
+<p>KeyboardEvent.initKeyEvent方法用于初始化使用{{domxref("document.createEvent")}}("KeyboardEvent")创建的事件的值。 以这种方式初始化的事件必须使用{{domxref("document.createEvent")}}("KeyboardEvent")方法创建。 在调度之前,必须调用initKeyEvent来设置事件。</p>
+
+<p><strong>不要再使用这个方法,而是使用{{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}}构造函数。</strong><br>
+ 该方法基于{{SpecName("DOM2 Events")}}的早期草案,并在基于Gecko的浏览器中实现; 其他浏览器基于{{SpecName("DOM3 Events")}}的早期草稿实现{{domxref("KeyboardEvent.initKeyboardEvent")}}。 将现代构造函数结构视为构建事件的唯一跨浏览器方式。</p>
+
+<h2 id="Syntax" name="Syntax">Syntax</h2>
+
+<pre><em>event</em>.initKeyEvent (<em>type</em>, <em>bubbles</em>, <em>cancelable</em>, <em>viewArg</em>,
+ <em>ctrlKeyArg</em>, <em>altKeyArg</em>, <em>shiftKeyArg</em>, <em>metaKeyArg</em>,
+ <em>keyCodeArg</em>, <em>charCodeArg</em>)
+</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt><em><code>type</code></em></dt>
+ <dd>是表示事件类型的{{domxref("DOMString")}}。</dd>
+ <dt><em><code>bubbles</code></em></dt>
+ <dd>是{{jsxref("Boolean")}}指示事件是否应该通过事件链冒泡(请参阅冒泡)。</dd>
+ <dt><em><code>cancelable</code></em></dt>
+ <dd>是{{jsxref("Boolean")}}我指出事件是否可以被取消(见可取消)。</dd>
+ <dt><em><code>viewArg</code></em></dt>
+ <dd>指定{{domxref("UIEvent.view")}}; 此值可能为空。</dd>
+ <dt><em><code>ctrlKeyArg</code></em></dt>
+ <dd>如果要生成的虚拟键是包含<kbd>Ctrl</kbd>键的键的组合,则为{{jsxref("Boolean")}}</dd>
+ <dt><em><code>altKeyArg</code></em></dt>
+ <dd><em><code>如果要生成的虚拟键是包含</code></em><kbd>Alt</kbd><em><code>键的键的组合,则为{{jsxref("Boolean")}}。</code></em></dd>
+ <dt><em><code>shiftKeyArg</code></em></dt>
+ <dd>A {{jsxref("Boolean")}}如果要生成的虚拟键是包含<kbd>Shift</kbd>键的键组合,则返回true。</dd>
+ <dt><em><code>metaKeyArg</code></em></dt>
+ <dd><em><code>是{{jsxref("Boolean")}}如果要生成的虚拟键是包含</code></em><kbd>Meta</kbd><em><code>键的键的组合,则为true。</code></em></dd>
+ <dt><em><code>keyCodeArg</code></em></dt>
+ <dd>是一个无符号长整型,表示被按下的键的虚拟键码值,否则为0.请参阅{{domxref("KeyboardEvent.keyCode")}}以获取键码列表。</dd>
+ <dt><em><code>charCodeArg</code></em></dt>
+ <dd>是一个无符号长整型,表示与按下的键相关的Unicode字符,否则为0。</dd>
+</dl>
+
+<h2 id="Example" name="Example">Example</h2>
+
+<pre>var event = document.createEvent('KeyboardEvent'); // create a key event
+// define the event
+event.initKeyEvent("keypress", // typeArg,
+ true, // canBubbleArg,
+ true, // cancelableArg,
+ null, // viewArg, Specifies UIEvent.view. This value may be null.
+ false, // ctrlKeyArg,
+ false, // altKeyArg,
+ false, // shiftKeyArg,
+ false, // metaKeyArg,
+ 9, // keyCodeArg,
+ 0); // charCodeArg);
+
+document.getElementById('blah').dispatchEvent(event);
+</pre>
+
+<h2 id="Specification" name="Specification">Specification</h2>
+
+<p>键盘事件的这种实现基于DOM 2事件早期版本中的关键事件规范,后来从该规范中删除。</p>
+
+<p>initKeyEvent是DOM Level 3事件的当前Gecko等价物(最初起草并且不推荐使用{{domxref("KeyboardEvent.KeyboardEvent", "KeyboardEvent()")}} {{domxref("Keyboard.initKeyboardEvent()")}}方法与以下参数:</p>
+
+<pre>typeArg of type DOMString
+canBubbleArg of type boolean
+cancelableArg of type boolean
+viewArg of type views::AbstractView
+keyIdentifierArg of type DOMString
+keyLocationArg of type unsigned long
+modifiersList of type DOMString);</pre>
+
+<p> </p>