aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/api/event/initevent/index.html
blob: a3c18c08a353930d397852c56f0fec41aba9f1a3 (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
---
title: Event.initEvent()
slug: Web/API/Event/initEvent
translation_of: Web/API/Event/initEvent
---
<div>{{ ApiRef("DOM") }}{{deprecated_header}}</div>

<p>The <strong><code>Event.initEvent()</code></strong> method is used to initialize the value of an {{ domxref("event") }} created using {{ domxref("Document.createEvent()") }}.</p>

<p>Events initialized in this way must have been created with the {{ domxref("Document.createEvent()") }} method. This method must be called to set the event before it is dispatched, using {{ domxref("EventTarget.dispatchEvent()") }}. Once dispatched, it doesn't do anything anymore.</p>

<div class="note">
<p><strong>Не используйте этот метод, т.к. он устаревший. (deprecated)</strong></p>

<p>Вместо него используйте такой специальный конструктор событий, как {{domxref("Event.Event", "Event()")}}. Страница <a href="/en-US/docs/Web/Guide/Events/Creating_and_triggering_events">Creating and triggering events</a> даст больше информации о возможностях использования.</p>
</div>

<h2 id="Syntax" name="Syntax">Синтаксис</h2>

<pre class="syntaxbox"><em>event</em>.initEvent(<em>type</em>, <em>bubbles</em>, <em>cancelable</em>);</pre>

<dl>
 <dt><em><code>type</code></em></dt>
 <dd>{{domxref("DOMString")}}, определяющая тип события.</dd>
 <dt><em><code>bubbles</code></em></dt>
 <dd>Is a {{jsxref("Boolean")}} deciding whether the event should bubble up through the event chain or not. Once set, the read-only property {{ domxref("Event.bubbles") }} will give its value.</dd>
 <dt><em><code>cancelable</code></em></dt>
 <dd>Is a {{jsxref("Boolean")}} defining whether the event can be canceled. Once set, the read-only property {{ domxref("Event.cancelable") }} will give its value.</dd>
</dl>

<h2 id="Example" name="Example">Пример</h2>

<pre><code>// Create the event.
var event = document.createEvent('Event');
</code>
// Create a click event that bubbles up and
// cannot be canceled <code>
event.initEvent('click', true, false);

// Listen for the event.
elem.addEventListener('click', function (e) {
  // e.target matches elem
}, false);

elem.dispatchEvent(event);</code>
</pre>

<h2 id="Спецификация">Спецификация</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Спецификация</th>
   <th scope="col">Статус</th>
   <th scope="col">Комментарий</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-event-initevent','Event.initEvent()')}}</td>
   <td>{{Spec2("DOM WHATWG")}}</td>
   <td>Начиная с {{SpecName('DOM2 Events')}} - deprecated, заменено на event constructors.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Events','##Events-Event-initEvent','Event.initEvent()')}}</td>
   <td>{{Spec2('DOM2 Events')}}</td>
   <td>Начальное определение.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.Event.initEvent")}}</p>

<h2 id="Смотрите_также">Смотрите также</h2>

<ul>
 <li>The constructor to use instead of this deprecated method: {{domxref("Event.Event", "Event()")}}. More specific constructors can be used too.</li>
</ul>