十种JavaScript事件处理的使用方法
来源:互联网 发布:买资料注册淘宝 编辑:程序博客网 时间:2024/04/28 02:14
1. onFocus:在用户为了输入而选择select、text、textarea等时
2. onBlur:在select、text、password、textarea失去焦点时
3. onChange:在select、text、textarea的值被改变且失去焦点时
4. onClick:在一个对象被鼠标点中时(button,checkbox,radio,link,reset,submit,text,textarea等)
5. onLoad:出现在一个文档完成对一个窗口的载入时
6. onUnload:当用户退出一个文档时
7. onMouseOver:鼠标被移动到一个对象上时
8. onMouseOut:鼠标从一个对象上移开时
代码同上
9. onSelect:当form对象中的内容被选中时
10. onSubmit:出现在用户通过提交按钮提交一个表单时
<html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onFocus="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onFocus="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
2. onBlur:在select、text、password、textarea失去焦点时
<html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onblur="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onblur="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
3. onChange:在select、text、textarea的值被改变且失去焦点时
<html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onChange="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="abc" onChange="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
4. onClick:在一个对象被鼠标点中时(button,checkbox,radio,link,reset,submit,text,textarea等)
<html>
<head>
</head>
<body>
<img src="xsd.jpg" onclick="alert('ok');"></img>
</body>
</html>
<head>
</head>
<body>
<img src="xsd.jpg" onclick="alert('ok');"></img>
</body>
</html>
5. onLoad:出现在一个文档完成对一个窗口的载入时
<html>
<head>
</head>
<body onLoad="javascript:alert('hello');" onUnload="javascript:alert('bye-bye');">
nihao
</body>
</html>
<head>
</head>
<body onLoad="javascript:alert('hello');" onUnload="javascript:alert('bye-bye');">
nihao
</body>
</html>
6. onUnload:当用户退出一个文档时
<html>
<head>
</head>
<body onLoad="javascript:alert('hello');" onUnload="javascript:alert('bye-bye');">
nihao
<form name="test">
<input type="text" name="t" value="hello" onSelect="javascript:alert('');">
<select name="se">
<option value="0">hehe</option>
<option value="1">hehe</option>
</select>
</form>
</body>
</html>
<head>
</head>
<body onLoad="javascript:alert('hello');" onUnload="javascript:alert('bye-bye');">
nihao
<form name="test">
<input type="text" name="t" value="hello" onSelect="javascript:alert('');">
<select name="se">
<option value="0">hehe</option>
<option value="1">hehe</option>
</select>
</form>
</body>
</html>
7. onMouseOver:鼠标被移动到一个对象上时
<html>
<head>
</head>
<body>
<img src="xsd.jpg" onmouseover="alert('over')" onmouseout="alert('out')"></img>
</body>
</html>
<head>
</head>
<body>
<img src="xsd.jpg" onmouseover="alert('over')" onmouseout="alert('out')"></img>
</body>
</html>
8. onMouseOut:鼠标从一个对象上移开时
代码同上
9. onSelect:当form对象中的内容被选中时
<html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="SXT" onSelect="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
<head>
</head>
<body>
<form name="test">
<input type="text" name="userName" value="SXT" onSelect="JavaScript:alert(document.test.userName.value);">
</form>
</body>
</html>
10. onSubmit:出现在用户通过提交按钮提交一个表单时
<html>
<head>
<script type="text/javascript">
function check() {
if(document.test.t.value == "") {
alert("空值");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="test" action="1.htm" onsubmit="return check();">
<input type="text" name="t">
<input type="submit" value="ok">
</form>
</body>
</html>
<head>
<script type="text/javascript">
function check() {
if(document.test.t.value == "") {
alert("空值");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="test" action="1.htm" onsubmit="return check();">
<input type="text" name="t">
<input type="submit" value="ok">
</form>
</body>
</html>
- 十种JavaScript事件处理的使用方法
- Qt事件处理的使用方法
- JavaScript的事件处理
- JavaScript的事件处理
- javascript事件处理的三种方式
- JavaScript事件处理的方式(三种)
- JavaScript的事件处理机制
- Javascript的事件处理机制
- JavaScript的事件处理程序
- JavaScript(js)处理的HTML事件、键盘事件、鼠标事件
- Javascript事件处理代码的三种写法
- JavaScript事件处理程序的3种方式
- JavaScript事件处理程序的3种方式
- Javascript事件处理程序的3种方式
- javascript处理事件的兼容写法
- javascript中一些简单事件的处理
- javascript中一些简单事件的处理
- JavaScript 事件处理程序的指派方式
- 如何制定学习计划 - 褪墨
- JavaScript程序编码规范
- 100条经典QQ
- 删除SATA硬盘安全删除硬件图标
- JDK中的jstat命令
- 十种JavaScript事件处理的使用方法
- 比较SQL Server 2005与SQL Server 2000分页技巧
- Java package从实践到理论
- 如何阅读源代码
- win2003系统服务备份与保护
- 值得看的网页
- 纯粹智能逻辑理论构想
- c# 使用独立的DLL来存储图片(资源文件)
- firefox中javascript获取本地时间中的年