各HTML元素可触发的事件
元素类型 |
事件列表 |
<a> |
onclick |
<acronym> |
onblur |
<address> |
onclick |
<area> |
onclick |
<b> |
onclick |
<bdo> |
onclick |
<big> |
onclick |
<blockquote> |
onclick |
<body> |
onresize |
<button> |
onresize |
<caption> |
onblur |
<cite> |
onresize |
<code> |
onresize |
<dd> |
onresize |
<del> |
onblur |
<dfn> |
onresize |
<div> |
onresize |
<dl> |
onresize |
<dt> |
onresize |
<em> |
onresize |
<fieldset> |
onresize |
<form> |
onsubmit |
<frame> |
onresize |
<frameset> |
onunload |
<h1> to <h6> |
onresize |
<hr> |
onresize |
<i> |
onresize |
<iframe> |
onblur |
<img> |
onresize |
<input> |
onresize |
<input type="text"> |
onselect |
<ins> |
onblur |
<kbd> |
onresize |
<label> |
onresize |
<legend> |
onresize |
<li> |
onresize |
<object> |
onresize |
<ol> |
onresize |
<p> |
onresize |
<pre> |
onresize |
<q> |
onblur |
<samp> |
onresize |
<select> |
onresize |
<small> |
onresize |
<span> |
onresize |
<strong> |
onresize |
<sub> |
onresize |
<sup> |
onresize |
<table> |
onresize |
<tbody> |
onblur |
<td> |
onblur |
<textarea> |
onselect |
<tfoot> |
onblur |
<th> |
onblur |
<thead> |
onblur |
<tr> |
onblur |
<tt> |
onresize |
<ul> |
onresize |
<var> |
onresize |
各JavaScript对象可触发的事件
对象类型 |
事件列表 |
button |
onblur |
checkbox |
onblur |
FileUpload |
onblur onchange |
form |
onsubmit |
frame |
onblur |
image |
onabort |
password |
onblur |
radio |
onblur |
reset |
onblur |
layer |
onblur |
select |
onchange |
submit |
onblur |
text |
onblur onchange |
textarea |
onblur onchange |
window |
onblur onunloadonselect |
Onkeydown事件举例1:功能:控制用户只能输入数字
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
if(keynum == 8 || keynum == 13 || ( keynum >= 48 && keynum <= 57)||(keynum >= 96 && keynum <= 105)){
return true;
}
else{
return false;
}
}
</script>
<form>
Type some text (numbers not allowed):
<input type="text" onkeydown="return noNumbers(event)" />
</form>
</html>
Onkeydown事件举例2:功能:将回车键当成Tab键
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JsEvent.aspx.cs" Inherits="js.JsEvent" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>JavaScript Event</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txtField1" />
<input type="text" id="txtField2" />
<input type="text" id="txtField3" />
</div>
</form>
<script type="text/javascript">
function fn_Ok() {
alert("Ok");
}
function body_keydown() {
//IE
if (window.event) {
if (event.keyCode == 13) {
//回车键
event.keyCode = 9;
}
}
}
document.onkeydown = body_keydown;
</script>
</body>
</html>
厦娲牖岵桓鲂≡驳悖扛?0毫?K