aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/globaleventhandlers/onchange/index.html
blob: 861bdf11f7ea9a0b69ed8fce4e4643eb77e538ad (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
---
title: GlobalEventHandlers.onchange
slug: Web/API/GlobalEventHandlers/onchange
translation_of: Web/API/GlobalEventHandlers/onchange
---
<p>{{ ApiRef() }}</p>

<h3 id="Summary" name="Summary">概述</h3>

<p><code>onchange</code>可以用来获取或设置当前元素的<code>change</code>事件的事件处理函数.</p>

<h3 id="Syntax" name="Syntax">语法</h3>

<pre class="eval">element.onchange = 事件处理函数
</pre>

<h3 id="Notes" name="Notes">备注</h3>

<p>下面的伪代码演示了,在Mozilla中,onchange事件是如何触发的:</p>

<pre>  control.onfocus = focus;
  control.onblur = blur;
  function focus () {
      original_value = control.value;
  }

  function blur () {
      if (control.value != original_value)
        control.onchange();
  }
</pre>

<p>因此,如果你在你的<code>focus</code><code>blur事件的处理函数里修改一个控件的值的话,</code>你可能遇到一些关于<code>change</code>事件意想不到的现象.另外, <code>change</code>事件是在<code>blur</code>事件发生之后才触发的. 这一点和IE不同.</p>

<h3 id="Specification" name="Specification">规范</h3>

<p>DOM Level 0不属于任何标准</p>

<h3 id="See_Also" name="See_Also">相关链接</h3>

<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-htmlevents">DOM Level 2: HTML event types</a></p>

<p>{{ languages( { "fr": "fr/DOM/element.onchange" ,"en": "en/DOM/element.onchange" } ) }}</p>