📄 dom_events.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML DOM Events</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>HTML DOM - Events</h1>
<a href="dom_using.asp"><img border="0" alt="previous" src="../images/btn_previous.gif" /></a>
<a href="dom_reference.asp"><img border="0" alt="next" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">Events are actions that can be detected by JavaScript.</p>
<hr>
<h2>Events</h2>
<p>By using JavaScript, we have the ability to create dynamic web pages. Events
are actions that can be detected by JavaScript.</p>
<p>Every element on a web page has certain events which can trigger JavaScript
functions. For example, we can use the onClick event of a button element to
indicate that a function will run when a user clicks on the button. We define
the events in the HTML tags.</p>
<p>Examples of events:</p>
<ul>
<li>A mouse click</li>
<li>A web page or an image loading</li>
<li>Mousing over a hot spot on the web page</li>
<li>Selecting an input box in an HTML form</li>
<li>Submitting an HTML form</li>
<li>A keystroke </li>
</ul>
<p><b>Note:</b> Events are normally used in combination with functions, and the
function will not be executed before the event occurs!</p>
<p>For a complete reference of the events supported by the HTML DOM, see our
<a href="dom_obj_event.asp">HTML DOM Event reference</a>.</p>
<hr>
<h2>onload and onUnload</h2>
<p>The onload and onUnload events are triggered when the user enters or leaves
the page.</p>
<p>The onload event is often used to check the visitor's browser type and
browser version, and load the proper version of the web page based on the
information.</p>
<p>Both the onload and onUnload events are also often used to deal with cookies
that should be set when a user enters or leaves a page. For example, you could
have a popup asking for the user's name upon his first arrival to your page. The
name is then stored in a cookie. Next time the visitor arrives at your page, you
could have another popup saying something like: "Welcome John Doe!".</p>
<hr>
<h2>onFocus, onBlur and onChange</h2>
<p>The onFocus, onBlur and onChange events are often used in combination with
validation of form fields.</p>
<p>Below is an example of how to use the onChange event. The checkEmail()
function will be called whenever the user changes the content of the field:</p>
<table class="ex" id="table9" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre><input type="text" size="30"
id="email" onchange="checkEmail()"></pre>
</td>
</tr>
</table>
<br />
<hr>
<h2>onMouseOver and onMouseOut</h2>
<p>onMouseOver and onMouseOut are often used to create "animated" buttons.</p>
<p>Below is an example of an onMouseOver event. An alert box appears when an
onMouseOver event is detected:</p>
<table class="ex" id="table11" border="1" cellspacing="0" width="100%">
<tr>
<td>
<pre><a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event');return false">
<img src="w3schools.gif" width="100" height="30">
</a></pre>
</td>
</tr>
</table>
<p><a target="_blank" href="../js/tryit.asp@filename=try_dom_tut_onmouseover">Try it
yourself</a></p>
<hr />
<a href="dom_using.asp"><img border="0" alt="previous" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="dom_reference.asp"><img border="0" alt="next" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -